Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/98675-what-am-i-doing-wrong/
Share on other sites

ok so i took out the ",$db" in the query so now it is

 

$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);

 

and that error went away.

 

so now here's the error:

 

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/public_html/search.php on line 128

 

Line 128 is:

$num = mysql_numrows($query);

 

here's the block of code:

 

$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); //This is line 128!
$index = 0;

Link to comment
https://forums.phpfreaks.com/topic/98675-what-am-i-doing-wrong/#findComment-505000
Share on other sites

i suggest that you consider an alternative record looping mechanism, for instance:

 

$query = "SELECT * FROM restaurants WHERE type='$type' $limit";
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);

while ($a_row = mysql_fetch_array($result)) {
      $name = $a_row['name'];
      $address = $a_row['address'];


      // etc. etc. etc.
}

Link to comment
https://forums.phpfreaks.com/topic/98675-what-am-i-doing-wrong/#findComment-505021
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.