Jump to content

[SOLVED] Help with previous and next button in gallery


rondog

Recommended Posts

I have a big video library in my database.

 

I have a video.php that displays whatever you video you clicked on from the list. On the video page I've made a previous and next link with a thumbnail of the previous and next videos. That was the easy part. The part I am having trouble with is if you are on the very first video, you are still able to click the link, except it breaks since there is nothing left. The same goes for the next button.

 

I just want the previous link to be inactive if its on the first one and the next button to be inactive if you're on the last one. I was thinking of just using mysql_num_rows which gets me the total videos for that particular camera/tape, but I cant think of any logic that could work with that. I cant use the videos ID since camera B, Tape 1, video 1 isnt at row 1..It comes after all of camera A Tape1 - 9. Here is what I am doing right now. Maybe you guys can think of something better?

 

That first block of php is just to get the next and previous images and links. Im trying to fix the prev and next problem right below that.

<?php
$current = $row[0];
$prev = $current - 1;
$next = $current + 1;
$getprev = mysql_query("SELECT vidname FROM videos WHERE id = '$prev'");
$prevrow = mysql_fetch_row($getprev);
$prevflv = $prevrow[0];
$previmg = str_replace(".flv",".jpg","$prevflv");
$checkprev = "cam_$c_loc/tape_$t_loc/imgs/$previmg";
$prevrplc = str_replace(".flv","","$prevflv");
$getnext = mysql_query("SELECT vidname FROM videos WHERE id = '$next'");
$nextrow = mysql_fetch_row($getnext);
$nextflv = $nextrow[0];
$nextimg = str_replace(".flv",".jpg","$nextflv");
$checknext = "cam_$c_loc/tape_$t_loc/imgs/$nextimg";
$nextrplc = str_replace(".flv","","$nextflv");

//fix end and beginning link issues
$numVids = mysql_query("SELECT id FROM videos WHERE tape = 'tape_$t_loc' AND camera = 'cam_$c_loc'");
$numvidcount = mysql_num_rows($numVids);
echo $numvidcount;//113
?>
<table width="0" border="0" align="center" cellpadding="3" cellspacing="3">
  <tr>
	<td>
	<?php
	if(file_exists($checkprev)) {
		echo("<a href=\"video.php?vid=cam_$c_loc/tape_$t_loc/$prevrplc&cam=$c_loc&tape=$t_loc\" target=\"_self\"><img src=\"cam_$c_loc/tape_$t_loc/imgs/$previmg\" width=\"100\" height=\"100\" alt=\"$previmg\" border=\"0\" /></a>");
	} else {
		echo("<a href=\"video.php?vid=cam_$c_loc/tape_$t_loc/$prevrplc&cam=$c_loc&tape=$t_loc\" target=\"_self\"><img src=\"nopic.jpg\" width=\"100\" height=\"100\" alt=\"$previmg\" border=\"0\" /></a>");
	}		
	?>
	</td>
	<td>
	<?php
	if(
	if(file_exists($checknext)) {
		echo("<a href=\"video.php?vid=cam_$c_loc/tape_$t_loc/$nextrplc&cam=$c_loc&tape=$t_loc\" target=\"_self\"><img src=\"cam_$c_loc/tape_$t_loc/imgs/$nextimg\" width=\"100\" height=\"100\" alt=\"$nextimg\" border=\"0\" /></a>");
	} else {
		echo("<a href=\"video.php?vid=cam_$c_loc/tape_$t_loc/$nextrplc&cam=$c_loc&tape=$t_loc\" target=\"_self\"><img src=\"nopic.jpg\" width=\"100\" height=\"100\" alt=\"$nextimg\" border=\"0\" /></a>");
	}		
	?>
	</td>
  </tr>
  <tr>
	<td><?php echo("<a href=\"video.php?vid=cam_$c_loc/tape_$t_loc/$prevrplc&cam=$c_loc&tape=$t_loc\" target=\"_self\"><div align=\"right\"><span class=\"prevnext\">« Prev</span></div></a>"); ?></td>
	<td><?php echo("<a href=\"video.php?vid=cam_$c_loc/tape_$t_loc/$nextrplc&cam=$c_loc&tape=$t_loc\" target=\"_self\"><span class=\"prevnext\">Next »</span></a>"); ?></td>
  </tr>
</table>

Link to comment
Share on other sites

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.