hey guys so im doing pagination...What am i doing wrong? heres my code:
//Begin Pagination
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
} // if
$query = "SELECT count(*) FROM restaurants WHERE type='$type'";
$result = mysql_query($query, $db) or trigger_error("SQL", E_USER_ERROR);
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];
$rows_per_page = 15;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno > $lastpage) {
$pageno = $lastpage;
} // if
if ($pageno < 1) {
$pageno = 1;
} // if
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query = "SELECT * FROM restaurants WHERE type='$type' $limit";
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
$num = mysql_numrows($query);
$index = 0;
while($num != $index) {
$name = mysql_result($sql, $index, "name");
//$address = mysql_result($quer, $index, "address");
$phone = mysql_result($sql, $index, "phone");
$hours = mysql_result($sql, $index, "hours");
$menu = mysql_result($sql, $index, "menu");
$type = mysql_result($sql, $index, "type");
$addr1 = mysql_result($sql, $index, "addr1");
$addr2 = mysql_result($sql, $index, "addr2");
$id = mysql_result($sql, $index, "id");
?>
<table width="503" align="center" class="result">
<tr>
<hr color="C9D7F1">
<td width="61" valign="middle"><img src="restpic.gif" alt="" /></td>
<td width="122"><p class="th3"><em class="result_name"><?php echo $name; ?></em><br />
<?php echo "$addr1, $addr2"; ?><br />
<a href="javascript:popUp_large('directions.php?daddr=<?php echo "$addr1, $addr2"; ?>');">Directions</a></p></td>
<td width="114"><p class="th3"><strong>Hours of Operation:<br />
</strong><?php echo $hours; ?></p></td>
<td width="137"><p class="th3"> <a href="listing.php?id=<?php echo $id; ?>#description">Description</a><br />
<?php
if($menu == "no") {
// DO NOTHING
}
else {
?>
<a href="<?php echo $menu; ?>" target="_blank">Menu</a> <br/>
<?php
}
?><a href="javascript:alert("For Reservations please call 1-800-566-3921");">Reservations</a><br />
<a href="preparepromo.php?promoname=<?php echo $id; ?>" target="_blank">Promotions</a></p></td>
</tr>
</table>
<?php
$index++;
}
if ($pageno == 1) {
echo " FIRST PREV ";
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> ";
$prevpage = $pageno-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> ";
} // if
echo " ( Page $pageno of $lastpage ) ";
if ($pageno == $lastpage) {
echo " NEXT LAST ";
} else {
$nextpage = $pageno+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> ";
} // if
//End Pagination
The error i get is:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/public_html/search.php on line 111
Fatal error: SQL in /home/public_html/search.php on line 111
Line 111:
$result = mysql_query($query, $db) or trigger_error("SQL", E_USER_ERROR);
any help is appreciated.
thanks