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
}
?>

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

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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.