Solved

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

Posted on 2009-06-28
1
189 Views
Last Modified: 2012-05-07
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
Comment
Question by:pingeyeg
1 Comment
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
SELECT id
     FROM product
     WHERE id<%d ORDER BY id desc ", $prodID);
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now