imperial109
Regular Member
- Jan 19, 2009
- 499
- 365
I don't like the 'standard' paging scripting that everyone suggests so I made my own.
It's set to display only 10 results per page and is for an image gallery. However, you don't have to update it to match the number of rows in your database. Suggestions about how to make it more simple/dynamic are welcome.
It's set to display only 10 results per page and is for an image gallery. However, you don't have to update it to match the number of rows in your database. Suggestions about how to make it more simple/dynamic are welcome.
PHP:
///get primary values
$gallery = $_REQUEST['gallery']; //define what type of images
$page = $_REQUEST['page']; //the page that you are on
//set parameters for results on one page
$offsetx = 0;
$rowsy = 10;
//if on the first page, we want to display the very first result in the table
//to get next 10, offsetx needs to be able to multiply
if ($page != 1) {$offsetx = 1;
$offsetx = $offsetx * 10;}
//query for total number of rows
$query = "SELECT * FROM `images` WHERE `type`='$gallery'";
$result = mysql_query($query);
$rows = mysql_num_rows($result);
//round up rows to multiple of 10 then divide by 10 to get number of pages
$roundup = ceil(intval($rows)/10)*10;
$t = $roundup/10;
$p = 1;
//display pages in chronological order 1,2,3,...
while ($t >= 1) {
echo "<a href=\"gallery.php?gallery=$gallery&page=$p\">$p</a> ";
$p++;
$t--;
}
//query for images and show only 10 results per page
$query = "SELECT * FROM `images` WHERE `type`='$gallery' LIMIT $offsetx,$rowsy";
$result = mysql_query($query);
//display gallery thumbnails
while($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
$id = $row['id'];
$img = $row['image'];
echo "<a href=\"gallery.php?view=$id\"><img src=\"$img\" border=0 height=150 width=150></a>";
}