Jump to content

Limiting an echo function to specified results


ryanwood4

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.