Link to home
Start Free TrialLog in
Avatar of pingeyeg
pingeyeg

asked on

SQL statement is not grabbing the previous image, rather the very first image

I am using a mysql database, just for heads up.  I have a small gallery that is displaying 2 images at a time.  I have two arrows image, one left and one right.  The right image, when clicked, takes you to the next id in line and it works fine.  My issue is the left arrow, when clicked, does not take you to the previous id, rather it takes you to the very first id.  Any thoughts?
$prodID = $_GET['prodID'];
$prevItem = sprintf("SELECT id
     FROM product
     WHERE id<%d", $prodID);
     $itemPrev = mysql_query($prevItem) or die("Previous item was not grabbed because: " . mysql_error());
     $p = mysql_fetch_array($itemPrev);												    
     $prevID = $p['id'];
          echo "<div class='sidebarimagewrap'>" . (empty($prevID) ? "<span class='sidebararrowlf'></span>" : "<a href='/view-product-SL.php?prodID=$prevID'><img class='sidebararrowlf' src='images/btn-arrow-sidebar-lf.png' alt='' /></a>");

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial