Jump to content

Can only display 1 result from a database?


Username:

Recommended Posts

I'm writing a highscore board for a game and I can only display one value from a DB...  :shrug:

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.