Jump to content
David Varen

Help me please

Recommended Posts

Hi,

I have users table with userid column and money_transfer table which all the financial operations are in it.

how can I make that every financial operation which I make in money_transfer table will be connected to every user separately?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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();

Share this post


Link to post
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

Share this post


Link to post
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? 

 

Share this post


Link to post
Share on other sites

The money_transfer table must have a user_Id field. Does it have a user_id field?

Share this post


Link to post
Share on other sites
21 minutes ago, Ingolme said:

The money_transfer table must have a user_Id field. Does it have a user_id field?

how do i match the userid field from users to mony_transfer?

Share this post


Link to post
Share on other sites

You don't have to. The money_transfer table should have its own user_id field by which you search for records.

Share this post


Link to post
Share on other sites
11 hours ago, Ingolme said:

You don't have to. The money_transfer table should have its own user_id field by which you search for records.

you don't understand what I'm asking. 

please see the attached file and maybe you will understand.

bank.zip

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

Select Columns you want from both, tablename.columnname(comma separated) FROM both table names (comma separated) WHERE one table userid equals sessionid AND other userid equals sessionid.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...