Jump to content

Pagination Problem


centenial

Recommended Posts

Hi,

I'm having trouble with this pagination script. It's supposed to display 8 properties per page, with links to prev & next pages, however it only shows 6... and the previous/next links don't work with the DB Query.

[CODE]<?php

$method = $_GET['method'];
if ($method == "list") {
echo ' List Categories Here...';
} else {
  include 'admin/includes/config.php';
  $category = $_GET['category'];

  if(!isset($_GET['page'])){
      $page = 1;
  } else {
      $page = $_GET['page'];
  }
 
  // Define the number of results per page
  $max_results = 8;
 
  // Figure out the limit for the query based
  // on the current page number.
  $from = (($page * $max_results) - $max_results);
 
  // Perform MySQL query on only the current page number's results
  $sql = "select l.id, l.l_id, l.state, l.price, l.s_desc, l.picture1, t.name As town from listings l
INNER JOIN towns t ON t.id = l.t_id
WHERE l.c_id = '$category' AND status = '1'
ORDER BY l.id DESC
LIMIT $from, $max_results";
 
  $result = mysql_query($sql) or die(mysql_error());
 

if (mysql_num_rows($result) <= 0) {
echo "We're sorry, there are currently no properties listed in this category. Please check back soon!";
} else {
while($row = mysql_fetch_array($result)){
      // Build your formatted results here.
          $id=$row["id"];
          $l_id=$row["l_id"];
          $t_id=$row["town"];
          $state=$row["state"];
          $price=$row["price"];
          $s_desc=$row["s_desc"];
          $picture1=$row["picture1"];
 
  //results
 
echo "
<div style='margin-top: .5cm; width: 95%;'>
<a href='detail.php?id=$id'><img src='admin/$picture1' width='175' border='0' align='left' hspace='4'></a>
<b>$t_id, $state</b><br />
<b>Listing ID:</b> $l_id<br />
<b>Price:</b> $price<br />
<br />
<div style='font-size: 9pt;'>
$s_desc <a href='detail.php?id=$id'>
More...</a></div>
</div>";
          }
 
 
  // Figure out the total number of results in DB:
  $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM listings"),0);
 
  // Figure out the total number of pages. Always round up using ceil()
  $total_pages = ceil($total_results / $max_results);
 
  // Page Number Hyperlinks
  echo "<br /><br />Page #: ";
 
  // Previous Link
  if($page > 1){
      $prev = ($page - 1);
      echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\">&lt;&lt; Previous</a>&nbsp;&nbsp;";
  }
 
  for($i = 1; $i <= $total_pages; $i++){
  if(($page) == $i){
  echo "$i";
  } else {
  echo " <a href=\"".$_SERVER['PHP_SELF']."?page=$i&category=$category&name=$name\">$i</a> ";
  }
  if(($i + 30) % 30 == 0)
  {
  echo '';
  }
  }
 
  // Next Link
  if($page < $total_pages){
      $next = ($page + 1);
      echo "&nbsp;&nbsp;<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next &gt;&gt;</a>";
}
}
}
?>[/CODE]
Can anybody help?
Link to comment
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.