Solved

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

Posted on 2009-06-28
1
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 143

Accepted Solution

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

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

'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 …
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

627 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