I show one video per page from category and with buttons next/previous user can navigate to next or previous id
in database. The problem is that when I am on the first video of that category the button previous
is still there and I can go one id previous which is another category. Same is with button next
. When user is on last video of that category the button for next is still there and can click on it which will load next id from database ( next category ).
if(isset($_GET['video_id']) && is_numeric($_GET['video_id']) && isset($_GET['video_cat_id']) && is_numeric($_GET['video_cat_id'])){
$video_id = $_GET['video_id'];
$video_cat_id = $_GET['video_cat_id'];
// get next picture id
$result = $pdo->prepare('SELECT video_id FROM video WHERE video_id > :video_id ORDER BY video_id ASC LIMIT 1');
if($result){
$result->execute(array(':video_id' => $video_id));
//$result->execute(array(':video_cat_id' => $video_cat_id));
if (($row = $result->fetch()) !== FALSE) {
$next_id = $row['video_id'];
}
}
// get previous picture id
$result = $pdo->prepare('SELECT video_id FROM video WHERE video_id < :video_id ORDER BY video_id DESC LIMIT 1');
if($result){
$result->execute(array(':video_id' => $video_id));
//$result->execute(array(':video_cat_id' => $video_cat_id));
if (($row = $result->fetch()) !== FALSE) {
$prev_id = $row['video_id'];
}
}
$result = $pdo->prepare("SELECT * FROM video WHERE video_id= :video_id LIMIT 1");
if ($result->execute(array(':video_id'=>$_GET['video_id'])))
{
$prev_button = (isset($prev_id) && $prev_id>0)?'<a href="vcat-'.$video_cat_id.'/video-'.$prev_id.'.html"><i class="fa fa-arrow-left fa-3x"></i></a>':'';
$next_button = (isset($next_id) && $next_id>0)?'<a href="vcat-'.$video_cat_id.'/video-'.$next_id.'.html"><i class="fa fa-arrow-right fa-3x"></i></a>':'';
if($row = $result->fetch())
{
// video goes here
What I saw is that in the query SELECT * FROM video WHERE video_id= :video_id LIMIT 1
I didn't select the category.
What I try is to make the query like this
$result = $pdo->prepare("SELECT * FROM video WHERE video_id= :video_id and video_cat_id = :video_cat_id LIMIT 1");
$result->bindParam(':video_id', $_GET['video_id'], PDO::PARAM_INT);
$result->bindParam(':video_cat_id', $video_cat_id, PDO::PARAM_INT);
if ($result->execute())
{
// video
But is loading me blank page. What can be the actual problem here?
UPDATE:
I make this
// get next picture id
$result = $pdo->prepare('SELECT video_id FROM video WHERE video_id > :video_id and video_cat_id = :video_cat_id ORDER BY video_id ASC LIMIT 1');
if($result){
$result->bindParam(':video_id', $_GET['video_id'], PDO::PARAM_INT);
$result->bindParam(':video_cat_id', $video_cat_id, PDO::PARAM_INT);
$result->execute();
if (($row = $result->fetch()) !== FALSE) {
$next_id = $row['video_id'];
}
}
same for previous picture - added video_cat_id in query. Then this:
$prev_button = '<a href="vcat-'.$video_cat_id.'/video-'.$prev_id.'.html"><i class="fa fa-arrow-left fa-3x"></i></a>':'';
$next_button = '<a href="vcat-'.$video_cat_id.'/video-'.$next_id.'.html"><i class="fa fa-arrow-right fa-3x"></i></a>':'';
if(isset($prev_id) && $prev_id > 0) { echo $prev_button; }
if(isset($next_id) && $next_id > 0) { echo $next_button; }
if($row = $result->fetch())
{
I've got the error:
PHP Parse error: syntax error, unexpected ':'