php - looking up results in another table and printing out on webpage


I print out on web page the user and avatar with the following code but wish to also add the users balance to the output which is in another table.. both tables share user although in the balance table there are users that are not registered in the user info table

Table userinfo

              user                  |        avatar        |

Table balances



29758b15-e021-4b3b-aad7-088b3843a9f6| Neido Toxx | 313b96f2-b9f1-4c8b-a3d0-5997d9a7bc1c| Marla Abbot | 98fde03e-377b-4b51-8ad6-6fb492e75298| Captian Grid ||||user | balance |


29758b15-e021-4b3b-aad7-088b3843a9f6| 1000 | 313b96f2-b9f1-4c8b-a3d0-5997d9a7bc1c| 0 | 98fde03e-377b-4b51-8ad6-6fb492e75298| 2500 | abcde03e-377b-4b51-8ad6-6fb492e75298| 0 | $result = mysql_query("SELECT user,avatar FROM userinfo"); if (!$result) { die("Query to show fields from table failed"); } $fields_num = mysql_num_fields($result); echo "<table><tr >"; // printing table headers for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); echo " <td>{$field->name}</td>"; } echo "</tr>\n"; // printing table rows while($row = mysql_fetch_row($result)) { echo "<tr>"; // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row as $cell) echo "<td>$cell</font></td>"; echo "</tr>\n"; } mysql_free_result($result);



select balance.user, info.avatar, balance.balance 
from user_balance balance
left join user_info info on info.user = balance.user 

People are also looking for solutions to the problem: how to show errors returned from php page on to jquery pop up


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.