Avatar of t3chguy
t3chguy
Flag for United States of America asked on

Php Mysql Pagination

I'm trying to display a photo gallery that puts the photos in rows of three, with a total of three rows a page (9 pictures a page).

The navigation in the script moves to page two, but the pictures do not change.  Also, I'm unable to navigate past page two, even though there are 12 pages.

<?php
require_once($_SERVER['DOCUMENT_ROOT']."/includes/header.php");
require_once("includes/sqlconnect.php");
?>
<div id="interiorpages">

<span class="pagetitle">Photo Gallery</span><br />
<div id="sectionunderline"></div><br />

<?php

if (isset($_GET['pageno']))
      {
      $pageno = $_GET['pageno'];
      }
      
else
      {
   $pageno = 1;
      }
      
$pageno = (int)$pageno;

if ($pageno > $lastpage)
      {
    $pageno = $lastpage;
      }

if ($pageno < 1)
      {
   $pageno = 1;
      }
      

$sql = "SELECT id, filename, category, width, height, filesize, caption, category, fileext, hidden FROM photos WHERE hidden = '0' ORDER BY width DESC";
$res = mysql_query($sql) or die(mysql_error());
$numrows = mysql_num_rows($res);

$rows_per_page = 9;
$lastpage = ceil($numrows/$rows_per_page);

$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;

$sql2 = "SELECT id, filename, category, width, height, filesize, caption, category, fileext, hidden FROM photos WHERE hidden = '0' ORDER BY width DESC $limit";

$res2 = mysql_query($sql2) or die(mysql_error());
$num2 = mysql_num_rows($res2);

if ($pageno == 1)
      {
      echo " FIRST PREV ";
      }

else
      {
      echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> ";
      $prevpage = $pageno-1;
      echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> ";
      }
      
echo " ( Page $pageno of $lastpage ) ";

if ($pageno == $lastpage)
      {
      echo " NEXT LAST ";
      }

else
      {
      $nextpage = $pageno+1;
      echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> ";
      echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> ";
      }

echo '<table width="960px" cellspacing="2" cellpadding="2" border="0" align="center">';

$count = 0;

for ($a = 0; $a < $num2; $a++)
      {
       echo '<tr>';
     for($count=0;$count<3;$count++)
        {
            $id = mysql_result($res2,$a,0);
            $filename = mysql_result($res2, $a, 1);
            $category = mysql_result($res2, $a, 2);
            $w = mysql_result($res2, $a, 3);
            $h = mysql_result($res2, $a, 4);
            $caption = mysql_result($res2, $a, 6);
            $category = mysql_result($res2, $a, 7);

            $width = ($w/8);
            $height = ($h/8);
            
            if ($w == '287')
                  {
                  $width = ($w * 0.84);
                  }
                  
            if ($w == '640')
                  {
                  $width = ($w/2.7);
                  }
                  
            if ($w == '960')
                  {
                  $width = ($w/4);
                  }
                  
            if ($w == '1315')
                  {
                  $width = ($w/5.6);
                  }
                  
            if ($w == '1363')
                  {
                  $width = ($w/5.7);
                  }

            if ($w == '1504')
                  {
                  $width = ($w/6.3);
                  }
                  
            if ($w == '1536')
                  {
                  $width = ($w/6.4);
                  }
                  
            if ($w == '1600')
                  {
                  $width = ($w/6.7);
                  }
                  
            if ($w == '2048')
                  {
                  $width = ($w/8.5);
                  }
                  
            if ($w == '2448')
                  {
                  $width = ($w/10.2);
                  }
                  
            if ($w == '3264')
                  {
                  $width = ($w/13.6);
                  }
                  
            
            else
                  {
                  $width = ($w / 7);
                  }
            
            
          echo '<td>
                         <a href="viewpicture.php?id='.$id.'" class="iframe"><img src="images/gallery/' . $filename . '.jpg"
                         width="'.$width.'px" border = "0"> </span></a><br /><br />
                         ' .$caption . '
                  </td>';
                  
           $a++;
        }
         echo '</tr>';
        $a--;
    }
      
      
echo '</table>';

require_once($_SERVER['DOCUMENT_ROOT']."/includes/footer.php");?>
PHP

Avatar of undefined
Last Comment
Ray Paseur

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy