PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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:
// 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>';
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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.