David Varen Posted April 23, 2020 Share Posted April 23, 2020 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? Link to comment Share on other sites More sharing options...
Ingolme Posted April 23, 2020 Share Posted April 23, 2020 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. Link to comment Share on other sites More sharing options...
David Varen Posted April 25, 2020 Author Share Posted April 25, 2020 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 More sharing options...
Ingolme Posted April 25, 2020 Share Posted April 25, 2020 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 More sharing options...
David Varen Posted April 26, 2020 Author Share Posted April 26, 2020 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 More sharing options...
Ingolme Posted April 26, 2020 Share Posted April 26, 2020 The money_transfer table must have a user_Id field. Does it have a user_id field? Link to comment Share on other sites More sharing options...
David Varen Posted April 26, 2020 Author Share Posted April 26, 2020 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? Link to comment Share on other sites More sharing options...
Ingolme Posted April 26, 2020 Share Posted April 26, 2020 You don't have to. The money_transfer table should have its own user_id field by which you search for records. Link to comment Share on other sites More sharing options...
David Varen Posted April 27, 2020 Author Share Posted April 27, 2020 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 Link to comment Share on other sites More sharing options...
Ingolme Posted April 27, 2020 Share Posted April 27, 2020 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 More sharing options...
dsonesuk Posted April 27, 2020 Share Posted April 27, 2020 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now