Jump to content

help needed to show previous photos in my photo gallery


peacehunter

Recommended Posts

Recently I am working with my php based photo gallery. I am successfully done to show next photos . which code is...

 $query2=mysql_query("SELECT ID2 FROM `upload2`");//For next photo$array2=mysql_fetch_array($query2);$num_row=mysql_num_rows($query2);$num_row=$num_row-1;$session=$_SESSION['counter']++;if($session==$num_row||$session>$num_row){$_SESSION['counter']=0;}$result4=mysql_result($query2,$session);echo "<a href=show_pic.php?hidden=$result4> Next pic</a>";

But if I add the code of previous photo..

 $query2=mysql_query("SELECT ID2 FROM `upload2`");//For previews photo$array2=mysql_fetch_array($query2);$num_row=mysql_num_rows($query2);$num_row=$num_row-1;$session=$_SESSION['counter']--;if($session==$num_row||$session<$num_row){$_SESSION['counter']=0;}$result4=mysql_result($query2,$session);echo "<a href=show_pic.php?hidden=$result4> Next pic</a>";

then php executes both code for next and previous photo ... as a result nothing is happen... nothing means what I want to do........In this situation I can only show link of next or previous photo ,not both.Plzzzz tell me how can I show the link of both next and previous photo.

Link to comment
Share on other sites

For one, don't use the session. I'm not sure what you're trying to use the counter variable for, but you should be able to see that one piece of code increases it and one decreases it, so it's always going to be 0. So, it's not very useful.Just send the next page the picture number to show, and use LIMIT in the SQL query to only get that one image. The next and previous links don't need to look up anything in the database, the previous link is just one less of the current and the next link is one more than the current.Check here for a description of LIMIT, find the word "limit" on this page and you'll see the examples:http://dev.mysql.com/doc/refman/5.1/en/select.html

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...