Hey guys, Great forum!!
So...im a newbie, well not really...i've been using PHP For a long time...so basically im Senior Newbie.
Well here's my problem: I'm making pagination for my website search results of the top 1,000 restaurants and it works fine...EXCEPT when i press Next it gives me the "No Results" page. So can anyone figure it out and help me? Thanks. My code is as follows:
<?php
//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) or trigger_error("SQL", E_USER_ERROR);
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];
$rows_per_page = 10;
$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($result);
while ($a_row = mysql_fetch_array($result)) {
$name = $a_row['name'];
//$address = mysql_result($quer, $index, "address");
$phone = $a_row['phone'];
$hours = $a_row['hours'];
$menu = $a_row['menu'];
$type = $a_row['type'];
$addr1 = $a_row['addr1'];
$addr2 = $a_row['addr2'];
$id = $a_row['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="onHandleRequest('GetDirections'); ?>');">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="onHandleRequest('GetDescription');">Description</a><br />
<?php
if($menu == "no") {
// DO NOTHING
}
else {
?>
<a href="<?php echo $menu; ?>" target="_blank">Menu</a> <br/>
<?php
}
?></td>
</tr>
</table>
<?php
}
if ($pageno == 1) {
echo " First Previous ";
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>First</a> ";
$prevpage = $pageno-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>Previous</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
?>