Hello all,

I seem to be having a problem with pagination. I would like to have pictures and information in boxes pulled from the database, but have 4 of them in a row, making a total of 8 put on each page. Can anyone help me figure this out?

Thanks in advance,
~Amy

<?php
session_start();

include ("databaseinfo.php");

$category=$_GET['category'];
$category=htmlspecialchars($category);
$category_sq=mysql_real_escape_string($category);

//count number of records 
$result = mysql_query("SELECT * FROM $category_sq WHERE active=\"1\"");
$num_rows = mysql_num_rows($result);
 
if(mysql_num_rows($result) == 0) {
  echo "<font size=\"4\" face=\"Arial\"><center>No results were found.</center>";
  exit;
}

//number you want to display per page
$page_rows=8;
 
//count number of pages
//This tells us the page number of last page
//How many pages
$last=ceil($num_rows/$page_rows);
 
 
//determine results
//This checks to see if there's a page number.  If not, it will set it to page 1.
if(isset($_GET['pagenum'])) {
  $pagenum=$_GET['pagenum'];
}
else{
  $pagenum=1;
}
if(($pagenum<1) || ($pagenum>$last)) $pageNum=1;
$offset=($pagenum-1)*$page_rows;

echo "<table style=\"FONT-SIZE: 11pt\" face=\"Arial\" align=center border=\"1\" cellspacing=\"10\">";
echo "<tbody>";
echo "<tr>";

$sql="SELECT * FROM $category_sq WHERE active=\"1\"";
$result=mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) 
{
$propnum=$row["propnum"];
$propnum=htmlspecialchars($propnum);
$descript=$row["description"];
$descript=htmlspecialchars($descript);
$tdescript=$row["thumbdescription"];
$tdescript=htmlspecialchars($tdescript);
$line1=$row["line1"];
$line1=htmlspecialchars($line1);
$line2=$row["line2"];
$line2=htmlspecialchars($line2);
$by=$row["by"];
$by=htmlspecialchars($by);
$price=$row["price"];
$price=htmlspecialchars($price);
$regpic=$row["fileName"];
$regpic=htmlspecialchars($regpic);
$thumb=$row["fileNameT1"];
$thumb=htmlspecialchars($thumb);
$tdescript=$row["thumbdescription"];
$tdescript=htmlspecialchars($tdescript);
$hover=$row["fileNameT2"];
$hover=htmlspecialchars($hover);

echo "<td><center><a href=\"http://www.thissite.com/folder/item.php?ID=$propnum\"><img src='$thumb' border=\"0\"></a><br>";
echo "<a href=\"http://www.thissite.com/folder/item.php?ID=$propnum\">";
echo $line1;
echo "<br>";
echo $line2;
echo "<br>";
echo $by;
echo "</a>";
echo "</td>";
echo "</center>";
}

echo "</tr>";
echo "</tbody>";
echo "</table>";

//This shows what page user's on and total pages
echo "<br><br>";
echo 

"--Page $pagenum of $last--<p>";
 
//Create links
if ($pagenum ==1)
{
}
else
{
echo "<a href='{$_SERVER['PHP_SELF']}?category=$category_sq&amp;pagenum=1'> <<-First</a> ";
echo " ";
$previous=$pagenum-1;
echo "<a href='{$_SERVER['PHP_SELF']}?category=$category_sq&amp;pagenum=$previous'> <-Previous</a> ";
}
 
//This checks if on last page and generates links
if ($pagenum ==$last)
{
}
else {
$next = $pagenum+1;
echo "<a href='{$_SERVER['PHP_SELF']}?category=$category_sq&amp;pagenum=$next'>Next -></a>";
echo " ";
echo "<a href='{$_SERVER['PHP_SELF']}?category=$category_sq&amp;pagenum=$last'>Last ->></a>";
}
?>

No worries...I got it figured out myself.

~Amy

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.