Jump to content

PHP Pagination fomatting and display Question


webguync

Recommended Posts

Hello,

 

I am working on a page that outputs results from a MySQL table into an HTML table via PHP. I have limited the results to around 25  per page. The code then paginates the remaining results. There are about 250 results so that creates about 144 page links at the bottom. What I want to do is have a link to result pages 1-5, 5-10, 10-15, and then a more link. How can I do that?

 

here is the current code:

 

if($rows > $ByPage)
		{
			$ListingTable .=  "<br><table align=center width=510>";
			$ListingTable .= "<td align=center><font face=verdana size=2> | ";

			$pages = ceil($rows/$ByPage);

			for($i = 0; $i <= ($pages); $i++)
			{
				$PageStart = $ByPage*$i;

				$i2 = $i + 1;

				if($PageStart == $Start)
				{
					$links[] = " <span class=RedLink>$i2</span>\n\t ";
				}
				elseif($PageStart < $rows)
				{
					$links[] = " <a class=BlackLink href=\"search.php?Start=$PageStart&c=$_GET[c]&s=$_GET[s]&AgentID=$_GET[AgentID]&search_city=$_GET[search_city]&search_state=$_GET[search_state]&search_country=$_GET[search_country]&search_PropertyType=$_GET[search_PropertyType]&MinPrice=$_GET[MinPrice]&MaxPrice=$_GET[MaxPrice]&rooms1=$_GET[rooms1]&rooms2=$_GET[rooms2]&bath1=$_GET[bath1]&bath2=$_GET[bath2]&before=$_GET[before]&school=$_GET[school]&transit=$_GET[transit]&park=$_GET[park]&ocean_view=$_GET[ocean_view]&lake_view=$_GET[lake_view]&mountain_view=$_GET[mountain_view]&ocean_waterfront=$_GET[ocean_waterfront]&lake_waterfront=$_GET[lake_waterfront]&river_waterfront=$_GET[river_waterfront]&city=$_GET[city]&p=$_GET[p]&r=$_GET[r]\">$i2</a>\n\t ";
				}
			}

			$links2 = implode(" | ", $links);

			$ListingTable .= $links2;

			$ListingTable .= "| </td>";

			$ListingTable .= "</table><br>\n";

		}
}

 

and page I am referring to:

 

http://www.upsetbids.com/search_test.php

 

thanks in advance

I found a pagination script that I am trying out, but I am getting no results being returned from my Query and I am not sure why. The  SQL should be producing results. What would be the best way to determine why no results are being returned? I have all of the variables set up correctly, I do believe.

 

<?
//CONNECT TO DATABASE
$db_name="MyDB";
$table_name ="MyTable";
$connection = @mysql_connect("localhost", "UserName", "pw")
or die (mysql_error());
$db = @mysql_select_db($db_name, $connection) or die (mysql_error());

$t = mysql_query("SELECT * FROM $table_name WHERE 'id' = '".addslashes($_GET['id'])."'");
  if(!$t) die(mysql_error());

$a = mysql_fetch_object($t);
$total_items= mysql_num_rows($t);
$limit = $_GET['limit'];
$type = $_GET['type'];
$page= $_GET['page'];

//set default if: $limit is empty, non numerical, less than 10, greater than 50
if((!$limit)  || (is_numeric($limit) == false) || ($limit < 10) || ($limit > 50)) {
     $limit = 10; //default
}
//set default if: $page is empty, non numerical, less than zero, greater than total available
if((!$page) || (is_numeric($page) == false) || ($page < 0) || ($page > $total_items)) {
      $page = 1; //default
}

//calcuate total pages
$total_pages     = ceil($total_items / $limit);
$set_limit          = $page * $limit - ($limit);

//query:

$q = mysql_query("SELECT * FROM $table_name WHERE 'id' = '".addslashes($_GET['id'])."' LIMIT $set_limit, $limit");
  if(!$q) die(mysql_error());
     $err = mysql_num_rows($q);
       if($err == 0) die("No Results Found.");

//Results per page: **EDIT LINK PATH**
echo("
<a href=www.inspired-evolution.com/Pagination.php?id=$id&limit=10&page=1>10</a> |
<a href=www.inspired-evolution.com/Pagination.php?id=$id&limit=25&page=1>25</a> |
<a href=www.inspired-evolution.com/Pagination.php?id=$id&limit=50&page=1>50</a>");

//show data matching query:
while($code = mysql_fetch_object($q)) {
     echo("item: ".$code->title."<BR>");
}

$id = urlencode($id); //makes browser friendly

//prev. page: **EDIT LINK PATH**

$prev_page = $page - 1;

if($prev_page >= 1) {
  echo("<b><<</b> <a href=http://www.inspired-evolution.com/Pagination.php?id=$id&limit=$limit&page=$prev_page><b>Prev.</b></a>");
}

//Display middle pages: **EDIT LINK PATH**

for($a = 1; $a <= $total_pages; $a++)
{
   if($a == $page) {
      echo("<b> $a</b> | "); //no link
     } else {
  echo("  <a href=http://www.inspired-evolution.com/Pagination.php?id=$id&limit=$limit&page=$a> $a </a> | ");
     }
}

//next page: **EDIT THIS LINK PATH**

$next_page = $page + 1;
if($next_page <= $total_pages) {
   echo("<a href=http://www.inspired-evolution.com/Pagination.php?id=$id&limit=$limit&page=$next_page><b>Next</b></a> > >");
}

//all done
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.