suicide1405241470 0 Report post Posted September 10, 2004 I'm using the following to retrieve data from stat_table<?php/* Include Files *********************/session_start(); include("database.php");include("login.php");/*************************************/echo "<table border=1>";$query = "SELECT STAT1 FROM stat_table WHERE GAME_ID=1 ORDER BY STAT1 DESC";$result = mysql_query($query) or die(mysql_error()); //runs the query$p=1;while($row=mysql_fetch_row($result)){$i=0;while ($i < mysql_num_fields($result)){$field_name=mysql_fetch_field($result, $i);echo "<tr><td>$p</td>" . "<td>" . $row[$i] . "</td></tr>";$i++;$p++;}}echo "</table>";?>This displays the following:1 yki 2 fy I also have user ID stored within stat_table, which corresponds to the user_id stored within the table user_table. I'm very new to php/mysql and I can't get my head around doing the following:Getting the user_id along with STAT1 from stat_table and then using the user_id to extract user_name from user_table and put it alongside the relevent STAT1 in the table above (the yki, fy bit). Share this post Link to post Share on other sites
The Mortgage Man 0 Report post Posted September 15, 2004 Assuming mySQL syntax is SQL 92 compliant try a simple join:"SELECT STAT1 FROM stat_table WHERE GAME_ID=1 ORDER BY STAT1 DESC";SELECT a.stat1, a.userid, b.usernameFROM stat_table a, user_table bWHERE a.userid = b.userid AND a.game_id = 1ORDER BY 1 DESC;This should get you close. I am confused however, because your ORDER BY clause should produce2 fy1 ykiinstead of what is in your post.js Share this post Link to post Share on other sites
Hercco 0 Report post Posted September 15, 2004 That should work on MySQL. And the order is right. See the numbers are just values of the variable p which is incremented on every round of the loop. So "fy" and "yki" are the entries that the database orders. Share this post Link to post Share on other sites