Hey Everyone!
I'm trying to create a photo database that returns 12 thumbnails/page in 4 columns and 3 rows. Everything works great, but I can't get the rows to break after 4 thumbs are displayed!
Also, I'm having trouble preventing the "NEXT" link from displaying on the last page of the gallery.
PLEASE HELP! I'm sure this has been covered before, but I'm new to this and can't find an example that I can reference.
Most code is based off of the "PREV 123 NEXT" article on this site.
<?php
// create connection
$connection = mysql_connect("","","") or die ("Couldn't connect to server.");
// select database
$db = mysql_select_db("dottv33", $connection) or die ("Couldn't select database.");
// create SQL query
$sql = "SELECT PIC_ID, TN_ID, SET_ID, PATH1, PATH2
FROM PICS";
// execute SQL query and get results
$limit=12; // rows to return
$numresults=mysql_query($sql,$connection) or die ("Couldn't execute query.");
$numrows=mysql_num_rows($numresults);
// next determine if offset has been passed to script, if not use 0
if (empty($offset)) {
$offset=0;
}
// get results
$result=mysql_query("SELECT PIC_ID, TN_ID, SET_ID, PATH1, PATH2 FROM PICS limit $offset,$limit");
<<<< BEGIN THIS IS WHERE I NEED HELP >>>>
// now you can display the results returned
echo "<TABLE BORDER=1>";
echo "<TR>";
while ($row=mysql_fetch_array($result)) {
// include code to display results as you see fit
$PIC_ID = $row["PIC_ID"];
$TN_ID = $row["TN_ID"];
$SET_ID = $row["SET_ID"];
$PATH1 = $row["PATH1"];
$PATH2 = $row["PATH2"];
echo "<TD><a href=\"$PATH1/$PIC_ID\"><img src=\"$PATH2/$TN_ID\"></a></TD>";
}
echo "</TR>";
echo "</TABLE>";
<<<< END THIS IS WHERE I NEED HELP >>>>
// next we need to do the links to other results
if ($offset>0) { // bypass PREV link if offset is 0
$prevoffset=$offset-12;
print "<a href=\"$PHP_SELF?offset=$prevoffset\">PREV</a> \n";
}
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
for ($i=1;$i<=$pages;$i++) { // loop thru
$newoffset=$limit*($i-1);
print "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> \n";
}
// check to see if last page
if (!(($offset/$limit)==$pages) && $pages!=0) {
// not last page so give NEXT link
$newoffset=$offset+$limit;
print "<a href=\"$PHP_SELF?offset=$newoffset\">NEXT</a><p>\n";
}
?>
Thanks for any tips!!!
newskool99 (Rich)