With the following script I've been trying to figure out how to do a while loop that does the following:
Takes the value of $asd to be 1(see below) and use that to be the number after STAT. This is to produce STAT1. Then I want to go through the rest of the script with the SELECT affecting the column STAT1. After that I want it to add 1 to $asd, then return to where I SELECT STAT$asd making it be 2, producing STAT2, then going through it all again.
I know I need a while loop, but I just can't get my head around how to do it. Also the fact that theres already a while loop in there seems to make it even more difficult to conceive. Can Anyone help me out?
<?php
/* Include Files *********************/
session_start();
include("database.php");
include("login.php");
/*************************************/
if(!$logged_in) {
echo "<a href='http://www.ffenigma.co.uk/main.php'>Log in to post your score</a>";
}
else {
$gamez = addslashes($_GET['game']);
$gn = str_replace("_", " ", $gamez);
$querya = "SELECT GAME_ID FROM game_table WHERE GAME_NAME='$gn'";
$resulta = mysql_query($querya) or die(mysql_error()); //runs the query
$rowa=mysql_fetch_row($resulta);
echo "<a href='http://www.ffenigma.co.uk/test.php'>Post your scores</a>";
}
echo "<table border=1><tr><td>Position</td><td>Score</td><td>Username</td></tr>";
$asd = 1;
$query = "SELECT STAT$asd, user_id FROM stat_table WHERE GAME_ID='$rowa[0]' ORDER BY STAT$asd DESC LIMIT 0, 10";
$result = mysql_query($query) or die(mysql_error()); //runs the query
$p=1;
while($row=mysql_fetch_row($result))
{
$query = "SELECT username FROM users WHERE userid=". $row[1];
$u_result = mysql_query($query);
$user = mysql_fetch_row($u_result);
echo "<tr><td>$p</td>" . "<td>" . $row[0] . "</td><td>". $user[0] ."</td></tr>";
$p++;
}
echo "</table>";
?>
I wasn't sure wether this was a database or php problem, so I added it here (I'm pretty sure it would be classed as a php problem)$end = 3; // just set the value to the number you need
$asd = 1;
while ($asd <= $end)
{
$query = "SELECT STAT". $asd .", user_id FROM stat_table WHERE GAME_ID='$rowa[0]' ORDER BY STAT". $asd ."DESC LIMIT 0, 10";
$result = mysql_query($query) or die(mysql_error());
$stat[$asd] = mysql_fetch_row($result);
}
then $stat[] is an array of all the results.Thanks, I just couldn't figure it out
Takes the value of $asd to be 1(see below) and use that to be the number after STAT. This is to produce STAT1. Then I want to go through the rest of the script with the SELECT affecting the column STAT1. After that I want it to add 1 to $asd, then return to where I SELECT STAT$asd making it be 2, producing STAT2, then going through it all again.
I know I need a while loop, but I just can't get my head around how to do it. Also the fact that theres already a while loop in there seems to make it even more difficult to conceive. Can Anyone help me out?
<?php
/* Include Files *********************/
session_start();
include("database.php");
include("login.php");
/*************************************/
if(!$logged_in) {
echo "<a href='http://www.ffenigma.co.uk/main.php'>Log in to post your score</a>";
}
else {
$gamez = addslashes($_GET['game']);
$gn = str_replace("_", " ", $gamez);
$querya = "SELECT GAME_ID FROM game_table WHERE GAME_NAME='$gn'";
$resulta = mysql_query($querya) or die(mysql_error()); //runs the query
$rowa=mysql_fetch_row($resulta);
echo "<a href='http://www.ffenigma.co.uk/test.php'>Post your scores</a>";
}
echo "<table border=1><tr><td>Position</td><td>Score</td><td>Username</td></tr>";
$asd = 1;
$query = "SELECT STAT$asd, user_id FROM stat_table WHERE GAME_ID='$rowa[0]' ORDER BY STAT$asd DESC LIMIT 0, 10";
$result = mysql_query($query) or die(mysql_error()); //runs the query
$p=1;
while($row=mysql_fetch_row($result))
{
$query = "SELECT username FROM users WHERE userid=". $row[1];
$u_result = mysql_query($query);
$user = mysql_fetch_row($u_result);
echo "<tr><td>$p</td>" . "<td>" . $row[0] . "</td><td>". $user[0] ."</td></tr>";
$p++;
}
echo "</table>";
?>
I wasn't sure wether this was a database or php problem, so I added it here (I'm pretty sure it would be classed as a php problem)$end = 3; // just set the value to the number you need
$asd = 1;
while ($asd <= $end)
{
$query = "SELECT STAT". $asd .", user_id FROM stat_table WHERE GAME_ID='$rowa[0]' ORDER BY STAT". $asd ."DESC LIMIT 0, 10";
$result = mysql_query($query) or die(mysql_error());
$stat[$asd] = mysql_fetch_row($result);
}
then $stat[] is an array of all the results.Thanks, I just couldn't figure it out