Display Images one by one with next and previous functionality

I have stored images in a separate folder (images) and created a database that stores letterNumber and with each letterNumber several images are associated.

The table (annimages) is as follows.

letterNo, imageNo, path, height, width 1 1 images/1a 700 630 1 2 images/1b 710 628 1 3 images/1c 705 630 `

Likewise I have 20 letters.

Now in PHP, I am able to retrive images on the web page with the following code.

$query="SELECT letterNo, width, height, path from annimages where letterNo=".$letterNumber; $rs=mysql_query($query,$connection); while ($row=mysql_fetch_array($rs)) { echo '<br/>'; echo '<img src="' .$row['path'].'.jpg"' .' width="'.$row['width'].'" height="'.$row['height'].'" alt=Letter "'.$letterNumber.'" />'. '<br/>'; }

The problem is: when I click from navigation bar letter number = 1, it will display all images associated with letter number 1. All in one click but I want to show images one by one with next and previous hyperlink.


You are only using 1 filtering field you need to use both (letteNo and imageNo)

$query="SELECT letterNo, width, height, path from annimages where letterNo=".$letterNumber." AND imageNo=".$imageNo." LIMIT 1"; $rs=mysql_query($query,$connection); $row=mysql_fetch_array($rs) echo '<br/>'; echo '<img src="'.$row['path'].'.jpg"'.'width="'.$row['width'].'"height="'.$row['height'].'" alt=Letter "'.$letterNumber.'" />'.'<br/>';

mysql LIMIT keyword limits how many rows are returned, though you dont need it if each combination of letterNo and imageNo relate to a single row. Though it is good to have a limit incase you dont catch all mysql injection attacks.

and each previous next link will need to pass the next letterNo and imageNo

And of course do as Madara Uchiha suggests in his comment and use mysqli api as the mysql api is depreciated


  • cURL not working while fetching Google API data
  • output json array in php
  • Handle Authentication and Authorization in jax-rs webservice with cxf
  • How to get text which is not part of any element using jsoup?
  • Using a join with three tables when a field might be null
  • Storing data from SQL in array
  • Insert records into two table at once
  • Is it possible to specialize on a static lifetime?
  • Get a trait object reference from a vector
  • Randomizing -and remembering that randomisation- multiple choice questions in php
  • what makes a request a new request in asp.net C#
  • Add dynamic data to line chart from mysql database with highcharts
  • Check for zero lines output from command over SSH
  • nonblocking BIO_do_connect blocked when there is no internet connected
  • How does this usort cmp function actually work?
  • Stop Bash Script if Hive Fails
  • How to add git credentials to the build so it would be able to be used within a shell code?
  • ActiveRecord query for a count of new users by day
  • Can you perform a UNION without a subquery in SQLAlchemy?
  • MailKit: The IMAP server replied to the 'EXAMINE' command with a 'BAD' response
  • PostgreSQL Query without WHERE only ORDER BY and LIMIT doesn't use index
  • Using $this when not in object context
  • javascript inside java/jsp code
  • htaccess rewriting URLs with multiple forward slashes
  • Upload files with Ajax and Jquery
  • ORA-29908: missing primary invocation for ancillary operator
  • Web-crawler for facebook in python
  • How to get next/previous record number?
  • Unanticipated behavior
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • A cron job substitute?
  • SQL merge duplicate rows and join values that are different
  • Acquiring multiple attributes from .xml file in c#
  • How do you join a server to an Active Directory (domain)?
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How does Linux kernel interrupt the application?
  • How can I remove ASP.NET Designer.cs files?
  • Can't mass-assign protected attributes when import data from csv file
  • Unable to use reactive element in my shiny app
  • java string with new operator and a literal