ok i am making this small gallery script that i ahve working but what i want to do is make it so that i display only 16 images per pageand have a next and previous button on the bottom, befor i started codeing to add the next and previous buttons i had no problems at all, but once i started imy thoughts ran astray and now i am going comepletely nuts, any help will be greatlt appreciated, my code is bellow
This is the code when i started to put the page feature, it works 100% just no next previous buttons.
<?php
$page = $_REQUEST['page'];
if($page <= 0){
$firstnum = '0';
$secondnum = '16';
$img1 = '<a>';
$img2 = '<a>';
}else {
$firstnum = $page * 16 + 1;
$secondnum = $page * 16 + 16;
}
echo '<div align="left"><img src="images/gallery.gif" width="152" height="42" /><p>';
$db_host = 'localhost'; //mySQL location
$db_user = 'root'; //mySQL server Username
$db_pass = 'pass'; //mySQL server password
$db_data = 'db'; //mySQL database
$link = mysql_connect($db_host, $db_user, $db_pass);
$dbsel = mysql_select_db($db_data);
$query = 'SELECT *
FROM gallery
ORDER BY postdate DESC limit '.$firstnum.','.$secondnum.'';
$result = mysql_query($query);
if(!$result){
echo mysql_error();}
else
{
$i=1;
$output .= '<table width="100%">';
while($piclist = mysql_fetch_array($result))
{
$j = $i%4; // What is left when we remove al multitudes of 4 from $i
if($j == 1) // First run: Add <tr>
{
$output .= "<tr>";
} $picture = $piclist['picname'];
$picid = $piclist['picid'];
$output .= '<td width="25%"><a href="/galpicinfo.php?picid='.$picid.'"><img src="gallery/'.$picture.'" width="80" height="80" /></a></td>';
if($j ==0) // Last of row: Add </tr>
{
$output .= "</tr>";
}
$i++;
}
for($j = $i%4; $j<4;$j++) // Finish the table
{
$output .= "<td></td>";
}}
$output .= "</table>";
echo $output;
?>
This is the script i have now when i attempted to add the next previous page.
<?php
$page = $_REQUEST['page'];
if($page <= 0){
$firstnum = '0';
$secondnum = '16';}
$db_host = 'localhost'; //mySQL location
$db_user = 'root'; //mySQL server Username
$db_pass = 'pass'; //mySQL server password
$db_data = 'db'; //mySQL database
$link = mysql_connect($db_host, $db_user, $db_pass);
$dbsel = mysql_select_db($db_data);
$q1 = 'SELECT *
FROM gallery
ORDER BY postdate DESC';
$r1 = mysql_query($q1);
$picamt = mysql_num_rows($r1);
$q2 = 'SELECT *
FROM gallery
ORDER BY postdate DESC limit '.$firstnum.','.$secondnum.'';
$r2 = mysql_query($q2);
$picamt2 = mysql_num_rows($r2);
if($picamt > $picamt2){
$firstnum = $page * 16 + 1;
$secondnum = $page * 16 + 16;
$img1 = '<a href="/?page='.$page+1 .'"><img src="images/next.gif"/></a>';
$img2 = '<a href="/?page='.$page-1 .'"><img src="images/prev.gif"/></a>';
}
echo '<div align="left"><img src="images/gallery.gif" width="152" height="42" /><p>';
$query = 'SELECT *
FROM gallery
ORDER BY postdate DESC limit '.$firstnum.','.$secondnum.'';
$result = mysql_query($query);
if(!$result){
echo mysql_error();}
else
{
$i=1;
$output .= '<table width="100%">';
while($piclist = mysql_fetch_array($result))
{
$j = $i%4; // What is left when we remove al multitudes of 4 from $i
if($j == 1) // First run: Add <tr>
{
$output .= "<tr>";
} $picture = $piclist['picname'];
$picid = $piclist['picid'];
$output .= '<td width="25%"><a href="/galpicinfo.php?picid='.$picid.'"><img src="gallery/'.$picture.'" width="80" height="80" /></a></td>';
if($j ==0) // Last of row: Add </tr>
{
$output .= "</tr>";
}
$i++;
}
for($j = $i%4; $j<4;$j++) // Finish the table
{
$output .= "<td></td>";
}}
$output .= "</table>";
echo $output;
echo '<table width="100%" border="0">
<tr>
<td align="right" valign="bottom">'.$img1.$img2.'</td>
</tr>
</table>';
?>
Again, i thank anyone who helps me with this, thanx