Jump to content

[SOLVED] click image to goto next image


Guber-X

Recommended Posts

okay so basicly it works but the problem is that when you try to view that last image, it doesnt load. and im lost in how to write the code. if anyone could help me out that would be great

 

link to page to see whats up lol

http://70.66.201.161/timeless/photos.php?cat_id=2&page=1

 

<?php
			echo "<br /><br />";				

			$result3 = mysql_query("SELECT * FROM photo_img WHERE pic_id=$pic_id LIMIT 1");
			if (!$result3) {
			   die("query failed: " . msql_error());
			}

			$result4 = mysql_query("SELECT * FROM photo_cat WHERE cat_id=$category ORDER by id LIMIT 1");
			if (!$result4) {
			   die("query failed: " . msql_error());
			}

			while ($row = mysql_fetch_array($result4)) {
				list($id, $cat_name, $cat_id, $location) = $row;		
			while ($row = mysql_fetch_array($result3)) {
				list($id, $pic_id, $file_name, $cat_id, $comment,) = $row;


			$resultNxt = mysql_query("SELECT * FROM photo_img WHERE cat_id=$category AND pic_id > $pic_id LIMIT 1");
			if (!resultNxt) {
				die("query failed: " . msql_error());
			}

			while ($nextrow = mysql_fetch_array($resultNxt)) {

			$nextimg = $nextrow['pic_id'];

			print('<a href=photos.php?cat_id='.$cat_id.'&thumb=full&pic_id='.$nextimg.'><img src="images/'.$location.$file_name.'" border="0"></a>');

			}
			}

			}
?>

Link to comment
https://forums.phpfreaks.com/topic/168055-solved-click-image-to-goto-next-image/
Share on other sites









$resultNxt = mysql_query("SELECT * FROM photo_img WHERE cat_id=$category AND pic_id > $pic_id LIMIT 1");









if (!resultNxt) {











die("query failed: " . msql_error());









}


















while ($nextrow = mysql_fetch_array($resultNxt)) {









$nextimg = $nextrow['pic_id'];




























print('<a href=photos.php?cat_id='.$cat_id.'&thumb=full&pic_id='.$nextimg.'><img src="images/'.$location.$file_name.'" border="0"></a>');




















}

 

You're relying on having a next image to display the current. When on the last image there isn't a next one...

 

if $resultNxt returns no results you need to display the current image with no link (or a link to the first)

try this;

 

<?php
echo "<br /><br />";
$result3 = mysql_query("SELECT * FROM photo_img WHERE pic_id=$pic_id LIMIT 1");
if (!$result3) {
die("query failed: " . msql_error());
}
$result4 = mysql_query("SELECT * FROM photo_cat WHERE cat_id=$category ORDER by id LIMIT 1");
if (!$result4) {
die("query failed: " . msql_error());
}
while ($row = mysql_fetch_array($result4)) {
list($id, $cat_name, $cat_id, $location) = $row;
while ($row = mysql_fetch_array($result3)) {
	list($id, $pic_id, $file_name, $cat_id, $comment,) = $row;
	$resultNxt = mysql_query("SELECT * FROM photo_img WHERE cat_id=$category AND pic_id > $pic_id LIMIT 1");
	if (!resultNxt) {
		die("query failed: " . msql_error());
	}
	if(mysql_num_rows($resultNxt) == 0) {
		print('<img src="images/'.$location.$file_name.'" border="0">');
	} else {
		while ($nextrow = mysql_fetch_array($resultNxt)) {
			$nextimg = $nextrow['pic_id'];
			print('<a href=photos.php?cat_id='.$cat_id.'&thumb=full&pic_id='.$nextimg.'><img src="images/'.$location.$file_name.'" border="0"></a>');
		}
	}
}
}
?>

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.