PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Right, I have loads of fields in my table for my game, I am making a highscores for my game and for example some one searches for their name and all the stats comes up
$totalinfo ="SELECT * FROM skillsoverall where playerName = '$player' ORDER BY xp DESC";
$totalinfo2 = mysql_query($totalinfo) or die ("Could not connect to players database.");
$totalinfo3 = mysql_fetch_array($totalinfo2);
How can I make it so it will show how many fields down '$player' is ?
I don't have a straight answer for you. In MySQL you can do this:
set @i = 0;
select playerName, @i:=@i+1 as myrow from skills
capture the above in a PHP variable and you should be in the right track
... and don't forget to sort the rows properly, the sample you provided does not sort by field XP, as your original post indicated
$rankinfo = "SELECT @i:=@i+1 AS myrow FROM skills WHERE playerName = '$player' ORDER BY xp DESC";
$rankinfo2 = mysql_query($rankinfo) or die ("Could not connect to players database.");
$rankinfo3 = mysql_fetch_array($rankinfo2);
$rankinfo = "SELECT playerName, @i:=@i+1 AS myrow FROM skills ORDER BY xp DESC";
$rankinfo2 = mysql_query($rankinfo) or die ("Could not connect to players database.");
$rankinfo3 = mysql_fetch_array($rankinfo2);
echo "<pre>";
var_dump($rankinfo3);
$rankinfo = "SELECT playerName, XP FROM skills WHERE playerName = '$player' ORDER BY xp DESC";
$rankinfo2 = mysql_query($rankinfo) or die ("Could not connect to players database.");
$i=0; // rank
while($row = mysql_fetch_array($rankinfo2))
{
echo "rank: ".$i++." player: ". $row['playerName']." XP: ".$row['XP']."<br />";
}