A little newbie here. I want to do simple pagination on this. This code show images from curent category. My goal is to show one image at the time and to have just 2 buttons for 'Prev' and 'Next' image. Any help is appreciate.
<?php
$cat_id = $_GET['cat_id'];
$query = "SELECT * FROM images WHERE img_category = '$cat_id' LIMIT 0, 1";
$result = mysqli_query($con, $query) or die("Query failed: " . mysqli_errno($con));
function getAllRows($dbResult) {
$rows = array();
while ($row = mysqli_fetch_assoc($dbResult)) { $rows[] = $row; }
return $rows; }
foreach ($rows = getAllRows($result) as $row) {
echo "<div id=\"picture\">";
echo "<img style=\"width:100%;margin:0 auto;\" src=\"upload/".$row['name']."\" /></a><br />";
echo "<div id=\"caption\">".$row['caption']."</div></div><br />"; }
if (count($rows) == 0) { echo "There is no images!\n"; }
I found some tutorial but something doesn't work as expected. Whenever I click 'Next' button doesn't load next image in this category but stay same image. Any help?
$q="select count(*) \"total\" from images";
$ros=mysqli_query($con, $q) or die(mysqli_error($con));
$row=mysqli_fetch_array($ros);
$total=$row['total'];
$dis=1;
$total_page=ceil($total/$dis);
$page_cur=(isset($_GET['page']))?$_GET['page']:1;
$k=($page_cur-1)*$dis;
$q="select * from images limit $k,$dis";
$ros=mysqli_query($con, $q);
echo '</table>';
echo '<br/>';
if($page_cur>1)
{
echo '<a href="pic.php?cat_id='.$cat_id.'&id='.($page_cur-1).'" style="cursor:pointer;color:green;" ><input style="cursor:pointer;background-color:green;border:1px black solid;border-radius:5px;width:120px;height:30px;color:white;font-size:15px;font-weight:bold;" type="button" value=" Previous "></a>';
}
else
{
echo '';
}
if($page_cur<$total_page)
{
echo '<a href="pic.php?cat_id='.$cat_id.'&id='.($page_cur+1).'"><input style="cursor:pointer;background-color:green;border:1px black solid;border-radius:5px;width:90px;height:30px;color:white;font-size:15px;font-weight:bold;" type="button" value=" Next "></a>';
}
else
{
echo '';
}
echo "</div>";