Jump to content

Help me please


David Varen
 Share

Recommended Posts

On 4/23/2020 at 11:57 PM, Ingolme said:

Have a field in the money_transfer table with the ID of the user involved. I'm not sure if I understood the question since this is trivial.

how this mysql supposed to look like?

     $mysqli = new mysqli("localhost","root",'',"bank");

if ($mysqli -> connect_errno) {
  echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
  exit();
}

$sql ="SELECT userid FROM users WHERE userid=$_SESSION[userid] UNION SELECT SUM(despoit-transferAmount) AS money from money_transfer";

if ($result = $mysqli -> query($sql)) {
 
 while ($obj = $result -> fetch_assoc()) {
    printf($obj->money."$");
  }
  $result -> free_result();
}

$mysqli -> close();

Link to comment
Share on other sites

It is not clear what you are trying to accomplish and I have no idea what your database table structure is.

Assuming the money_transfer table has a user_id field, here's how to get all transfers for a user: SELECT * from money_transfer WHERE user_id = 5

Link to comment
Share on other sites

23 hours ago, Ingolme said:

It is not clear what you are trying to accomplish and I have no idea what your database table structure is.

Assuming the money_transfer table has a user_id field, here's how to get all transfers for a user: SELECT * from money_transfer WHERE user_id = 5

I need to do the action "SELECT transferid,SUM(despoit-transferAmount) AS money from money_transfer" WHERE userid=$_SESSION[userid].

the userid is in the users table.

how do I combined the two tables so the action will work? 

 

Link to comment
Share on other sites

This is not a PHP problem, this is a database architecture problem. What is the structure of your money_transfer table? How is the relation between the money_transfer and the users table defined?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...