Username: Posted October 9, 2010 Share Posted October 9, 2010 I'm writing a highscore board for a game and I can only display one value from a DB... I don't know what I could be doing wrong. I've done this kind of DB work before. <?php $name = $_GET['lvl']; if($_GET['lvl']=="Strength"){ //1/21 $skill = "strlvl"; $exp = "strexp"; } else if($_GET['lvl']=="Attack"){ //2/21 $skill = "atklvl"; $exp = "atkexp"; } else if($_GET['lvl']=="Defence"){ //3/21 $skill = "deflvl"; $exp = "defexp"; } else if($_GET['lvl']=="Hitpoints"){ //4/21 $skill = "hplvl"; $exp = "hpexp"; } else if($_GET['lvl']=="Range"){ //5/21 $skill = "rglvl"; $exp = "rgexp"; } else if($_GET['lvl']=="Magic"){ //6/21 $skill = "mglvl"; $exp = "mgexp"; } else if($_GET['lvl']=="Hitpoints"){ //7/21 $skill = "hplvl"; $exp = "hpexp"; } else if($_GET['lvl']=="Prayer"){ //8/21 $skill = "prlvl"; $exp = "prexp"; } else if($_GET['lvl']=="Runecraft"){ //9/21 $skill = "rclvl"; $exp = "rcexp"; } else if($_GET['lvl']=="Slayer"){ //10/21 $skill = "sllvl"; $exp = "slexp"; } else if($_GET['lvl']=="Thieve"){ //11/21 $skill = "thlvl"; $exp = "thexp"; } else if($_GET['lvl']=="Agility"){ //12/21 $skill = "hplvl"; $exp = "hpexp"; } else if($_GET['lvl']=="Firemaking"){ //13/21 $skill = "fmlvl"; $exp = "fmexp"; } else if($_GET['lvl']=="Woodcut"){ //14/21 $skill = "wclvl"; $exp = "wcexp"; } else if($_GET['lvl']=="Cooking"){ //15/21 $skill = "cklvl"; $exp = "ckexp"; } else if($_GET['lvl']=="Herblore"){ //16/21 $skill = "hblvl"; $exp = "hbexp"; } else if($_GET['lvl']=="Mining"){ //17/21 $skill = "mnlvl"; $exp = "mnexp"; } else if($_GET['lvl']=="Farming"){ //18/21 $skill = "frmlvl"; $exp = "frmexp"; } else if($_GET['lvl']=="Fishing"){ //19/21 $skill = "fshlvl"; $exp = "fshexp"; } else if($_GET['lvl']=="Smithing"){ //20/21 $skill = "smlvl"; $exp = "smexp"; } else if($_GET['lvl']=="Fletching"){ //21/21 $skill = "fltlvl"; $exp = "fltexp"; } else if($_GET['lvl']==""){ //0/21 echo "<center><br /><br />No skill selected!</center><br />"; } mysql_connect("mysql", "15557_test", "**************") or die("Could not connect: " . mysql_error()); mysql_select_db("15557_test"); //STARTS HERE $result = mysql_query("SELECT playerName, $skill, $exp FROM skills ORDER BY $exp ASC LIMIT 5000"); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { echo"Skill: " . $name . "<br />"; printf("Player: %s - Rank: %s - EXP: %s<br />", $row[0],$row[1],$row[2]); mysql_free_result($result //ENDS HERE } ?> Link to comment https://forums.phpfreaks.com/topic/215475-can-only-display-1-result-from-a-database/ Share on other sites More sharing options...
Pikachu2000 Posted October 9, 2010 Share Posted October 9, 2010 The best place to start debugging this would probably be to echo your query string and paste it in to phpMyAdmin (or MySQL console prompt) to see how many results it returns. Link to comment https://forums.phpfreaks.com/topic/215475-can-only-display-1-result-from-a-database/#findComment-1120468 Share on other sites More sharing options...
Username: Posted October 9, 2010 Author Share Posted October 9, 2010 You mean like this? echo $result; Link to comment https://forums.phpfreaks.com/topic/215475-can-only-display-1-result-from-a-database/#findComment-1120471 Share on other sites More sharing options...
Rifts Posted October 9, 2010 Share Posted October 9, 2010 I dont think this makes sense "SELECT playerName, $skill, $exp FROM skills ORDER BY $exp ASC LIMIT 5000" Link to comment https://forums.phpfreaks.com/topic/215475-can-only-display-1-result-from-a-database/#findComment-1120473 Share on other sites More sharing options...
Username: Posted October 9, 2010 Author Share Posted October 9, 2010 How doesn't that query make sense? Link to comment https://forums.phpfreaks.com/topic/215475-can-only-display-1-result-from-a-database/#findComment-1120474 Share on other sites More sharing options...
kenrbnsn Posted October 9, 2010 Share Posted October 9, 2010 Change <?php $result = mysql_query("SELECT playerName, $skill, $exp FROM skills ORDER BY $exp ASC LIMIT 5000"); ?> to <?php $q = "SELECT playerName, $skill, $exp FROM skills ORDER BY $exp ASC LIMIT 5000"; echo "Query: $q <br />"; $result = mysql_query($q) or die("Problem with the query: $q<br />" . mysql_error()); ?> When the query prints paste it into phpmyadmin and see how many rows it returns. Ken Link to comment https://forums.phpfreaks.com/topic/215475-can-only-display-1-result-from-a-database/#findComment-1120477 Share on other sites More sharing options...
Username: Posted October 9, 2010 Author Share Posted October 9, 2010 "Showing rows 0 - 2 (3 total, Query took 0.0088 sec)" Link to comment https://forums.phpfreaks.com/topic/215475-can-only-display-1-result-from-a-database/#findComment-1120478 Share on other sites More sharing options...
PFMaBiSmAd Posted October 9, 2010 Share Posted October 9, 2010 The code you posted is freeing the mysql result inside of the loop: mysql_free_result($result), so of course you are only iterating through the loop once. Why did you put mysql_free_result($result) inside of the loop? Link to comment https://forums.phpfreaks.com/topic/215475-can-only-display-1-result-from-a-database/#findComment-1120480 Share on other sites More sharing options...
Username: Posted October 9, 2010 Author Share Posted October 9, 2010 The code you posted is freeing the mysql result inside of the loop: mysql_free_result($result), so of course you are only iterating through the loop once. Why did you put mysql_free_result($result) inside of the loop? love you solved Link to comment https://forums.phpfreaks.com/topic/215475-can-only-display-1-result-from-a-database/#findComment-1120484 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.