Jump to content

For Problem w/ SQL Queries


marcus

Recommended Posts

I am making a high scores table with awards and stuff, and when it inserts into the database the first rows is blank.

[code]
<?php
include('header.php');

$id = $_GET['id'];

if(!isset($id)){
error("This is not a valid game!");
}else {

$sql = "SELECT * FROM `gamenames` WHERE `gameid` =$id";
$res = mysql_query($sql) or die(mysql_error());

if(mysql_num_rows($res) == 0){
error("This is not a valid game!");
}else {
$sql = "SELECT * FROM `gamenames` WHERE `gameid` =$id";
$res = mysql_query($sql) or die(mysql_error());
$row2 = mysql_fetch_assoc($res);
$sql1 = "SELECT * FROM `highscores` WHERE `gameid` =$id ORDER BY `score` DESC LIMIT 100";
$res1 = mysql_query($sql1) or die(mysql_error());
$num = mysql_num_rows($res1);

if($num > 100){
$num = 100;
}
echo "<table border=0 cellspacing=3 cellpadding=2>\n";
echo "<tr><td colspan=2>Top $num High scores for $row2[gamename]</td></tr>";
echo "<tr><td colspan=2>Username</td><td>Score</td></tr>";
for($i = 1; $i <= $num; $i++){
$a1 = "SELECT * FROM `awards` WHERE `username` ='$row[username]' AND `gamename` ='Baanin Move'";
$a2 = mysql_query($a1) or die(mysql_error());
if($i >= 0 && $i <= 3){
if(mysql_num_rows($a2) == 0){
$sql = "INSERT INTO `awards` (`username`,`place`,`gamename`,`gid`) VALUES('$row[username]','1','$row2[gamename]','$row2[gameid]')";
$res = mysql_query($sql) or die(mysql_error());
}
}
if($i >= 4 && $i <= 8){
if(mysql_num_rows($a2) == 0){
$sql = "INSERT INTO `awards` (`username`,`place`,`gamename`,`gid`) VALUES('$row[username]','2','$row2[gamename]','$row2[gameid]')";
$res = mysql_query($sql) or die(mysql_error());
}
}
if($i >= 9 && $i <= 15){
if(mysql_num_rows($a2) == 0){
$sql = "INSERT INTO `awards` (`username`,`place`,`gamename`,`gid`) VALUES('$row[username]','3','$row2[gamename]','$row2[gameid]')";
$res = mysql_query($sql) or die(mysql_error());
}
}
$row = mysql_fetch_assoc($res1);
echo "<tr><td class=boardB>$i<td class=boardB><a href='profile.php?player=$row[username]'>$row[username]</a></td><td class=boardB>$row[score]</td></tr>\n";
}

echo "</table>";
}
}
include('footer.php');
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/33175-for-problem-w-sql-queries/
Share on other sites

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.