I was making a content management system for tutorials for my site, and I got this error on the category.php page where it show the list of categories.
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/genesis/public_html/category.php on line 99
<?php
include ("dbconnect.php");
$id = $_GET['id'];
if(!isset($_GET['page'])){
$page = 1;
}else{
$page = $_GET['page'];
}
$max_results = 50;
$from = (($page * $max_results) - $max_results);
?>
<h1>Newest Tutorials</h1>
<?php
$query = "SELECT * FROM `tutorials` WHERE category = '$id' ORDER BY id DESC LIMIT 0, 10";
$result = mysql_query($query) or die("Error in query: $query . " . mysql_error());
if(mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_row($result))
{
$query1 = "SELECT * FROM category WHERE id = ‘".$row[4]."‘";
$result1 = mysql_query($query1)
or die ("Error in query: $query1. " . mysql_error());
$row2 = mysql_fetch_object($result1);
$category = $row2->name;
?>
<table width="100%" cellpadding="3″ cellspacing="0″>
<tr>
<td width="40″><a href="viewtut.php?id=<?php echo $row[0]; ?>"><img src="../images/avatars/<?php echo $row[3]; ?>" alt="<?php echo $row[1]; ?>" height="40″ width="40″ border="0″></a></td>
<td valign="top" width="100%"><h2><a href="viewtut.php?id=<?php echo $row[0]; ?>"><?php echo $row[1]; ?></a></h2><b>Category: </b><?php echo $category; ?></td>
</tr>
<tr>
<td colspan="2″><?php echo $row[6]; ?></td>
</tr>
</table>
<hr>
<?php
}
}
?>
<?php
echo "<center>";
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM tutorials WHERE category = ‘$id’"),0);
$total_pages = ceil($total_results/$max_results);
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo"['.$i.']";
}else{
echo "<a href=’?page=$i’>$i</a> ";
} }
echo "<br>Page ".$page." of ".$total_pages;
echo "</span>";
mysql_close($connection);
?>
This is line 99
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM tutorials WHERE category = ‘$id’"),0);