Jump to content

Pagination Count Question; Simlar To An Earlier Thread


phpQuestioner

Recommended Posts

I had an idea last night to create a pagination script based on mysql limit and I saw a thread just a little bit ago that sparked my interest in doing something similar with my script as the script in that thread. I want to be able to limit how many pagination numbers can be seen at one time, but I want them to count up or down with the pagination and for the pagination urls to change - similar to a Google Search Results pagination.

 

Here Is Most of The Full Code:

 

<?php

// connect 
// select db

$thispage = $_SERVER['PHP_SELF'];

$amount = $_GET['skip'];

$next = $amount + $display;

$back = $amount - $display;

$results = mysql_query("select * from $mydt LIMIT $amount, $display");

$maxed_out = mysql_num_rows(mysql_query("select * from $mydt"));

$total_amount_of_pgs = $maxed_out / $display;

$currentpg = $amount / $display;

$tp = ceil($total_amount_of_pgs);

if ($currentpg > $total_amount_of_pgs)
{
$currentpg = $total_amount_of_pgs;
}

while($this=mysql_fetch_array($results)) {

// declare variables
$myfield=$this["field1"];

// display content
echo "$myfield<br>";

}

// Pagination

echo "<br><center>";

echo "<a href=\"$thispage?skip=$back\">Previous<a>"; 

for ($i = 0; $i < $tp; $i++)
{
$pganteqty = $display * $i;
$ci = $i + 1;
if ($ci<=3)
{
  echo " <a href=\"$thispage?skip=$pganteqty\">$ci</a> ";
}
else {
  echo " ........ ";
  break;
}
}

echo "<a href=\"$thispage?skip=$next\">Next<a>";

echo "<br><br>";

echo "Viewing Page ". floor($currentpg + 1) ."  of  ". ceil($total_amount_of_pgs) ."";

echo "</center>";

?>

 

And Here Is The Segment I'm Having Problems With:

 

for ($i = 0; $i < $tp; $i++)
{
$pganteqty = $display * $i;
$ci = $i + 1;
if ($ci<=3)
{
  echo " <a href=\"$thispage?skip=$pganteqty\">$ci</a> ";
}
else {
  echo " ........ ";
  break;
}
}

 

The above code will show only three numbers at a time, but it will not count up or down and it will not change pagination numbers or pagination urls.

 

How can I do this with my script?

This looks similar to your paging you can modify it, i am using these function to show paging...

<?php
## function to show paging.......
function showPaging($curpage)
{
global $sCurpageurl;
global $offset;
global $limit;
global $nTotalrows;
global $nTotalpage;
global $sOrderpagetype;
global $sOrderfield;

echo" <table width=100% border=0 cellspacing=0 cellpadding=5 >";
echo "<tr>";
$lastrowno=$offset+$limit;
if($lastrowno>=$nTotalrows)
$lastrowno=$nTotalrows;
if($nTotalrows==0)
$startrow=0;
else
$startrow=$offset+1;

echo"<td align=left width=50% ><b></b> " .$startrow ." - ". ($lastrowno) ." of ". $nTotalrows ."</td>";
echo"<td align=right width=50% >";
echo "<b>Page : </b>";


for($i=1;$i<=$nTotalpage;$i++)
{
$curOffset=($i-1)*$limit;
if($i==$curpage)
echo "<b> ".$i."</b>";
else
if ( strpos($sCurpageurl,"?")>0)
{
echo"  <a href=".$sCurpageurl."&offset=".$curOffset."&pno=".$i."&field=".$sOrderfield."&pord=".$sOrderpagetype." admin_menu_link>".$i."</a>"  ;
}
else
{
echo"  <a href=".$sCurpageurl."?offset=".$curOffset."&pno=".$i."&field=".$sOrderfield."&pord=".$sOrderpagetype." admin_menu_link>".$i."</a>"  ;
}
}
echo"</td></tr></table>";
}
## function to show total pages.......
function totalPages($strsql){
global $limit;
global $nTotalrows;
global $nTotalpage;
$rs1=mysql_query($strsql)or die("query failed11".mysql_error());
$rowno=mysql_num_rows($rs1);

if($rowno>0)
$nTotalpage=ceil($rowno/$limit);
else
$nTotalpage=0;
$nTotalrows=$rowno;
}
?>

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.