Hey, I was wondering if someone could help me out with my code...
It keeps giving me the following error:
Invalid query (Resource id #28) : You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #28' at line 1
Here is the code, please tell me what I did wrong and correct me 🙂
<?php
$db = mysql_connect("localhost","xxx","pw");
mysql_select_db (xxx);
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
$max_results = 25;
$from = (($page * $max_results) - $max_results);
$sql = mysql_query("SELECT * FROM files WHERE game='{$_REQUEST['game']}' ORDER BY name asc LIMIT $from, $max_results");
if (!$result = mysql_query($sql)) {
print "Invalid query ($sql) : " . mysql_error();
exit;
}
$num = mysql_num_rows($result);
if ($num < 1) {
echo "<div align=left><font color=#FFFFFF face=Verdana size=1>Sorry, there are <B>0</B> files in this category.";
}
else
{
while($row = mysql_fetch_array($result)) {
echo "<table width=100% cellpadding=0 cellspacing=0><tr>
<td width=40%>
<font face=Verdana size=1 color=b4bcb7><B>» </B><font face=Verdana size=2 color=FFFFFF><a href=file.php?id=".$row["id"]."><B>".$row["name"]."</B></td>
<td width=25%>
<font face=Verdana size=1 color=FFFFFF>".$row["creator"]."</B></td>
<td width=20%>
<font face=Verdana size=1 color=FFFFFF><center>".$row["submitted"]."</B></td>
<td width=15%>
<font face=Verdana size=1 color=FFFFFF><center>".$row["hits"]."</B></td></tr>
</table>";
}
}
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM files"),0);
$total_pages = ceil($total_results / $max_results);
echo "<font face=Verdana size=1 color=FFFFFF><br><B>Select a Page</B><br />";
if($page > 1){
$prev = ($page - 1);
echo "<a href=\"files.php?page=$prev\"><font face=Verdana size=1 color=b4bcb7><B>«</B><Previous</a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=\"files.php?page=$i\">$i</a> ";
}
}
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"files.php?page=$next\">Next <font face=Verdana size=1 color=b4bcb7><B>»</B></a>";
}
echo "";
?>