3raser Posted February 6, 2010 Share Posted February 6, 2010 Here is my current PHP & MySQL code: <?php mysql_connect("db4free.net","isrbuckey55","pgpg7755opcd") or die("Connection failed!"); mysql_select_db("isrbuckey55") or die("Database fail!"); //display data $get = mysql_query("SELECT * FROM views"); while ($row = mysql_fetch_assoc($get)) { // get data $time = $row['seconds']; } echo "Total gameplay seconds: ". $time ."<br><Br><br>"; //display data $get = mysql_query("SELECT * FROM scores ORDER BY score DESC"); while ($row = mysql_fetch_assoc($get)) { // get data $score = $row['score']; $username = $row['username']; } echo "The user ". $username ." got a score of ". $score .""; ?> Website link; http://z-o-cheats.webuda.com/ Why does it only display ONE highscore? Quote Link to comment https://forums.phpfreaks.com/topic/191114-only-echoes-one/ Share on other sites More sharing options...
premiso Posted February 6, 2010 Share Posted February 6, 2010 Because you only echo out that last result: while ($row = mysql_fetch_assoc($get)) { // echo data echo "The user ". $row['username'] ." got a score of ". $row['score'] .""; } Since there are multiple data you have to iterate through the results to print it and or collect them all into a multi-dimensional array and loop / iterate through that. Quote Link to comment https://forums.phpfreaks.com/topic/191114-only-echoes-one/#findComment-1007731 Share on other sites More sharing options...
3raser Posted February 6, 2010 Author Share Posted February 6, 2010 Doesn't work. Just gives me this: The user got a score of :/ Edit: Hold on, I added the code wrong. Let me test it again. Quote Link to comment https://forums.phpfreaks.com/topic/191114-only-echoes-one/#findComment-1007739 Share on other sites More sharing options...
premiso Posted February 6, 2010 Share Posted February 6, 2010 Then it seems you may have the wrong column names. As the only difference in the variation I posted is that I just echoed the data straight from the returned result array. Quote Link to comment https://forums.phpfreaks.com/topic/191114-only-echoes-one/#findComment-1007742 Share on other sites More sharing options...
3raser Posted February 6, 2010 Author Share Posted February 6, 2010 I added the code wrong. Let me test it again. Quote Link to comment https://forums.phpfreaks.com/topic/191114-only-echoes-one/#findComment-1007743 Share on other sites More sharing options...
3raser Posted February 6, 2010 Author Share Posted February 6, 2010 It works. Quote Link to comment https://forums.phpfreaks.com/topic/191114-only-echoes-one/#findComment-1007764 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.