Jump to content

Recommended Posts

I'm using the code below to display images from a database, then using the echo function to display them on the page. However, I also have arrows either side of the photo's so you can click next to see the next image in the database or previous to see the previous.

 

<?php
$con = mysql_connect("xxx","xxx","xxx");
if (!$con)
{
  die('Could not connect: ' . mysql_error());
}

mysql_select_db("xxx", $con);

$photoID = $_GET['photoID'];

$result = mysql_query("SELECT * FROM galleries WHERE photoID = '$photoID'");

while($row = mysql_fetch_array($result))
{
  $title = $row['photoTitle'];
  $image = $row['photoPath'];
  $body = $row['photoDescription'];
  $photoID = $row['photoID'];
  $credit = $row['photoCredit'];
}

mysql_close($con);
?> 

 

However, the echo function below causes a problem, for example if your on the last photo in the set, say id=51, and you press next it will reload the page, but because there isn't a photo with the id=52 it shows a blank page.

 

<? echo $photoID+1?>

 

How do you limit it, so that it either won't allow you to press next on the last image, or so it returns the first image in the set?

 

Thanks, hope that made sense.

 

Ryan

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.