View Full Version : Limiting records to a page and create paging

10-09-2007, 01:00 PM
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.....

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);
header("Location: gallery_detail.php?photographerID=$menu");


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


10-09-2007, 01:54 PM
try this tut


10-09-2007, 04:03 PM
Thanks David, I'll give it a crack and post how I get on.

Regards, Paul.

10-09-2007, 09:38 PM
i actually just created one of these here:


if you get stuck let me know.