Page 1 of 1
Page Numbering
Posted: Mon Mar 01, 2004 2:23 pm
by mccommunity
I am pulling a list of about 10,000 items. There are 25 items to display on the page at a time. I would like to ad page numbering at the top. I am able to add page numbering at the top fine but if there are 100 pages it displays page 1 - page 100 which takes up the whole screeen. I would like for whever it is over ten to display page 20 page 30 page 40 etc. I am not sure how to do this though. Can anyone help? Here is my code I am using:
Code: Select all
// Set up pagesets for all of the records.
$now_date = date("m-d-Y");
$query = "select count(1) from inventory where auction='$SESSIONїauction]' and consignor='$SESSIONїconsignor]' AND field1 >= '$now_date'";
if (!$c){
$c = pg_connect($runlistdb);
}
$r = pg_exec($c,$query);
$numrecords = pg_result($r,0,0);
$pages = $numrecords/$limit;
echo '<p class="nav"><center><table><tr>';
for ($p=0;$p<$pages;$p++){
$newoffset = $p*$limit;
if ($p > 0){
echo ' ';
}
echo "<td ><center><a href="$PHP_SELF?orderby=$orderby&sort=$sort&limit=$limit&offset=$newoffset">Page " . ($p+1) . '</a></center></td> ';
}
echo '</tr></table></td></tr></table>';
Posted: Tue Mar 02, 2004 5:43 pm
by ckuipers
I use this as a page navigator:
Code: Select all
Function Page_Navigator ($Offset, $DataBase, $Link, $Limit, $Show)
{
$Value = $Offset;
$result= MySQLQuery("SELECT * FROM $DataBase", "Sorry, A is temporarily unavailable.");
$Check2= mysql_num_rows($result);
$Pages= ceil($Check2/$Limit);
$LastPageOffset= ($Pages-1) * $Limit;
$NumHundreds= floor($Check2/(100*$Limit));
$ThisPage= ($Offset/$Limit) + 1;
$Hundreds= floor($ThisPage / 100);
$Temp= $ThisPage % 100;
$Tens= floor($Temp / 10);
$Rest= $Temp % 10;
$Check= $Check2 - $Value - $Limit;
echo "<TABLE>\n";
echo "<TR>\n";
echo "<TD WIDTH=20 HEIGHT=45> \n";
echo "</TD><TD WIDTH=80>\n";
if ($Offset != 0)
{
$Offset= $Value - $Limit;
echo "<A HREF="" . $Link . ".php?Offset=" . $Offset . """;
echo "onmouseover='switchImagesBack("on")' onmouseout='switchImagesBack("off")'>\n";
echo "<IMG NAME="imagenameBack" SRC="/Pictures/Back.jpg"></A>\n";
}
echo "</TD><TD ALIGN=CENTER>\n";
if ($Show == "1")
{
echo "<FONT COLOR=DARKRED><B>Page " . $ThisPage . " of " . $Pages . "</B></FONT><BR>\n";
## Show first line in Navigator.
## Calculate the start and end values first. Then Print and print current in Black.
$StartValue= (($Hundreds * 100) + ($Tens * 10) + 1);
$EndValue= (($Hundreds * 100) + ($Tens * 10) + 10);
echo "<A HREF="" . $Link . ".php?Offset=0"><SMALL><SMALL>First</SMALL></SMALL></A>\n";
for ($i=$StartValue; $i <= $EndValue; $i++)
{
$Offset= ($i - 1) * $Limit;
if ($Value == $Offset)
{
echo "<FONT COLOR="BLACK"><B> " . $i . "</B>\n";
}
else if ($Offset <= $Check2)
{
echo "<A HREF="" . $Link . ".php?Offset=" . $Offset . ""><SMALL><SMALL> " . $i . "</SMALL></SMALL></A>\n";
}
}
echo "<A HREF="" . $Link . ".php?Offset=" . $LastPageOffset . ""><SMALL><SMALL>Last</SMALL></SMALL></A>\n";
echo "<BR>";
for ($i=1; $i <= 10; $i++)
{
$Reali = ($i * 10) + ($Hundreds * 100);
$Offset= ($Reali - 1) * $Limit;
if ($Value == $Offset)
{
echo "<FONT COLOR="BLACK"><B> " . $Reali . "</B>\n";
}
else if ($Offset <= $Check2)
{
echo "<A HREF="" . $Link . ".php?Offset=" . $Offset . ""><SMALL><SMALL> " . $Reali . "</SMALL></SMALL></A>\n";
}
}
echo "<BR>";
for ($i=1; $i <= $NumHundreds; $i++)
{
$Reali = $i * 100;
$Offset= ($Reali - 1) * $Limit;
if ($Value == $Offset)
{
echo "<FONT COLOR="BLACK"><B> " . $Reali . "</B>\n";
}
else
{
echo "<A HREF="" . $Link . ".php?Offset=" . $Offset . ""><SMALL><SMALL> " . $Reali . "</SMALL></SMALL></A>\n";
}
}
}
else
{
echo " \n";
}
echo "</TD><TD WIDTH=80 ALIGN=RIGHT>\n";
if ($Check > 0)
{
$Offset= $Value + $Limit;
echo "<A HREF="" . $Link . ".php?Offset=" . $Offset . """;
echo "onmouseover='switchImagesForward("on")' onmouseout='switchImagesForward("off")'>\n";
echo "<IMG NAME="imagenameForward" SRC="/Pictures/Forward.jpg"></A>\n";
}
echo "</TD><TD WIDTH=20> \n";
echo "</TD></TR>\n";
echo "</TABLE>\n";
}
It selects the number of lines from a database, the limit is the number of items per page, link is the link to the page.
If you have more questions just lemme know.
Posted: Tue Mar 02, 2004 6:34 pm
by pickle
Hmm, you can find which page you're currently on, and you can output links to arbitrary pages. Those are the only two stumbling blocks I can think of. Why don't you just use the current offset and display links from $current_offset - 10 to $current_offset + 10.