logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 10-09-2007, 01:00 PM   #1
tux
tux's Avatar
 
Join Date: Feb 2007
Location: Isle of Wight, that little island right at the bottom of the UK
Posts: 657
Default Limiting records to a page and create paging

I have a gallery page that displays thumbnail images from my database. How can I limit the number of images displayed on a page and create the code needed for next/previous links to show the next set of thumbnails.

Here is my code so far.....

Code:
 
<?php
require_once("connections/connection.php"); // database connection
///////////////////////////////////////////
$photographerID  =   $_GET['photographerID'];
$imageID         =   $_POST{'imageID'}; 
$menu            =   $_POST['menu'];
///////////////////////////////////////////
///////////////////////////////////////////query for images
$query              =   sprintf("SELECT thumbURL FROM images where photographerID = '$photographerID'");
$result             =   @mysql_query($query);
$thumb              =   @mysql_num_rows($result);
///////////////////////////////////////////
$num_cols      = 3; //number of columns required
$num_rows      = ceil($thumb / $num_cols); // the number of rows ( total records returned divided by number of columns )
$num           = 0; //this zero because the first number of each record inside a record set is zero not 1
 
///////////////////////////////////////////
$query              =   sprintf("SELECT * FROM photographers ");
$result2             =   @mysql_query($query);
$photographerlist   =   @mysql_fetch_array($result2);
///////////////////////////////////////////
if($menu){
header("Location: gallery_detail.php?photographerID=$menu"); 
exit;
}
?>
--------------------------------------------------------------

Code:
 
<?php
echo "<table>"; //start the table
for ($rows = 0; $rows < $num_rows; $rows++) { //loop for the table rows
echo "<tr>"; 
for ($cols = 0; $cols < $num_cols; $cols++) { //loop for the table columns
if  ($num < $thumb) { // show records if available (reduce by one because the first record is zero
$thumb_row = mysql_result($result, $num, "thumbURL"); //create new variables with the values of the current record 
echo "<td>".$thumb_row."<br><td>";
} 
else { // show an empty cell
echo "<td>&nbsp;</td>";
}
$num++; // raise the number by one for the next record
}
echo "</tr>"; // no more cols in this row so close the table row 
}
echo "</table>"; // close the table
?>
Thanks
tux is offline   Reply With Quote
Old 10-09-2007, 01:54 PM   #2
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

try this tut

http://www.php-mysql-tutorial.com/php-mysql-paging.php
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 10-09-2007, 04:03 PM   #3
tux
tux's Avatar
 
Join Date: Feb 2007
Location: Isle of Wight, that little island right at the bottom of the UK
Posts: 657
Default

Thanks David, I'll give it a crack and post how I get on.

Regards, Paul.
tux is offline   Reply With Quote
Old 10-09-2007, 09:38 PM   #4
m1a2x3x7
m1a2x3x7's Avatar
 
Join Date: Mar 2007
Posts: 297
Default

i actually just created one of these here:

http://www.mcfeegallery.com/mcfee.php

if you get stuck let me know.
m1a2x3x7 is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:13 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com