marcus Posted January 7, 2007 Share Posted January 7, 2007 I am making a high scores table with awards and stuff, and when it inserts into the database the first rows is blank.[code]<?phpinclude('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] Quote Link to comment Share on other sites More sharing options...
trq Posted January 7, 2007 Share Posted January 7, 2007 Honestly, why are you making a seperate table for this? All this should be done with SELECT queries using your existing data. You are replicating data for no reason. Quote Link to comment Share on other sites More sharing options...
marcus Posted January 7, 2007 Author Share Posted January 7, 2007 Highscores is used to store the highscores. And awards is to store users awards. Quote Link to comment Share on other sites More sharing options...
trq Posted January 7, 2007 Share Posted January 7, 2007 I know what there for, they just seem a little redundant. Quote Link to comment Share on other sites More sharing options...
marcus Posted January 7, 2007 Author Share Posted January 7, 2007 Well, I didn't make the database, I'm just working for somebody. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.