ryanwood4 Posted February 2, 2010 Share Posted February 2, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/190712-limiting-an-echo-function-to-specified-results/ Share on other sites More sharing options...
taquitosensei Posted February 2, 2010 Share Posted February 2, 2010 if(($photoID+1) < mysql_num_rows($result)) { // echo your next code here } Quote Link to comment https://forums.phpfreaks.com/topic/190712-limiting-an-echo-function-to-specified-results/#findComment-1005765 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.