|
|
|
|
|
|
| |
This shows how to page thru a large resultset in a simple manner. It produces a set of links where-ever its called that looks like:
[ << 1 2 3 4 >> ]
and so on.
Bastien
|
<?php
/*
show_pages shows the links to the different pages
it gets passed the current offset and the total number of images to
show on one page ($display_length)
*/
function show_pages($offset, $display_length)
{
//run a query to see how many records there are total.
$total = ''; //resource handle for the query
$total_images = 0; //total number of elements in the paging system
$pages = 0; //number of pages calculated in the script
$base_offset = 0; //starting point for offsets
$show_pages = 3; //number of links to show as pages
$start_page = 1; //index number of the page to start with
echo "<table width='100%'><tr><td align='center'><b>[ ";
$sql = "select count(*) from photos";
$total = query($sql);
if (mysql_num_rows($total)==1)
{
$row = mysql_fetch_array($total);
$total_images = $row[0];
$pages = floor($total_images/$display_length); //calc the number of links to show (ceil rounds up to next int)
if ($pages > $show_pages)
{
$base_offset = $offset - $display_length;
//can't go past first page
if ($base_offset < 0){ $base_offset = 0; }
$start_page = $base_offset / $display_length;
$end_page = $show_pages + $start_page;
//can't go past last page
if ($end_page > $pages) { $end_page = $pages; }
}//end if
if ($start_page > 1)
{
echo "<a href=\"".$_SERVER['PHP_SELF']."?offset=".($base_offset-$display_length)."\"><<</a> ";
}
for ($x = $start_page ; $x <= $end_page; $x++)
{
//don't show current page as link
if ($base_offset == $offset)
{
echo "$x ";
}else{
echo "<a href=\"".$_SERVER['PHP_SELF']."?offset=$base_offset\">$x</a> ";
}//end if
$base_offset += $display_length;
}//next
if ($pages > $end_page)
{
echo "<a href=\"".$_SERVER['PHP_SELF']."?offset=$base_offset\">>></a> ";
}
}else{
echo "No other images found";
}
echo "]</b></td></tr></table>";
}//end function
?> | | |
|
| phpFormGenerator for Dynamic Form Generation from MySQL Categories : PHP, PHP Classes, MySQL, Databases, HTML and PHP | | | Functions for loading images into a MySQL database and displaying them. Categories : Graphics, HTML and PHP, MySQL, PHP, Databases | | | Dynamically generated pop-ups (Select items) Categories : PHP, HTML and PHP, MySQL, Databases | | | Message of the Day - Random Message (Needs MySQL!) Categories : Databases, HTML and PHP, PHP, MySQL | | | Required form fields that pull from MySQL database Categories : PHP, HTML and PHP, Databases, MySQL | | | mySQL/PHP/search with multientry
form and table output with colored rows Categories : PHP, Beginner Guides, MySQL, HTML and PHP, Databases | | | Creating thumbnails from MySQL Blobs online Categories : PHP, MySQL, Graphics, HTML and PHP, Databases | | | Function to do live population of HTML's <Select> tag from a Table Categories : PHP, MySQL, HTML and PHP, Databases | | | Storing / Retrieving pictures from database This can be used for banner / ads exchange. very useful for people developing big portal with ads in the site........ Categories : PHP, MySQL, Databases, HTML and PHP | | | Record Set Paging with PHP (RSP) Categories : PHP, MySQL, Navigation, Databases, HTML and PHP | | | Alternating background color for HTML table rows Categories : PHP, Databases, MySQL, HTML and PHP | | | Editing the virtusertable and sendmail.cw via PHP3.0 and Mysql Categories : MySQL, HTML and PHP, PHP, Databases | | | This function will populate the options in a drop down HTML select list
in a form from a database query.
Categories : MySQL, General SQL, PHP, HTML and PHP, Databases | | | html split bar used to split in multiple pages a database result Categories : HTML and PHP, Databases, MySQL, PHP | | | Database resultset navigation Categories : PHP, HTML and PHP, Databases, MySQL, Navigation | |
|
|