Solved

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

Posted on 2009-06-28
1
192 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
'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 …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 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