Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

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

0
pingeyeg
Asked:
pingeyeg
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
SELECT id
     FROM product
     WHERE id<%d ORDER BY id desc ", $prodID);
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now