A
A
Abay Tazhigaliev2016-02-08 07:37:47
PHP
Abay Tazhigaliev, 2016-02-08 07:37:47

How to make links to the previous and next video by title_url, like in the photo?

294a288aead14103b960c0c6196c8b07.jpg
Here is the video fetch request
function select_video($video,$lang,$start_pos, $perpage)
{
db_connect();
$query = " SELECT article.*,
(SELECT COUNT(*) FROM comments WHERE comments.note_id = article.title_url AND comments.lang = '$lang') AS comments_count
FROM video AS article
WHERE article.lang = '$lang' ORDER BY id DESC LIMIT $start_pos, $perpage ";
$result = mysql_query($query);
$result = db_result_to_array($result);
return $result;
}
/// Function for placing the results of the selection into an array
function db_result_to_array($result)
{
$res_array = array();
$count = 0;
while($row = @mysql_fetch_array($result))
{
$res_array[$count] = $row;
$count++;
}
return $res_array;
}
Now how to display a link and a button to the previous and next video?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey, 2016-02-08
@webcoderpro

Pass the current video's id and lang parameter to the function and that's enough

function select_video($id, $lang){
  db_connect();
  $query = "SELECT `video`.*, (SELECT count(c.`id`) FROM `comments` c WHERE c.`note_id` = `video`.`title_url` AND c.`lang` = '{$lang}') comments_count
        FROM `video` 
        WHERE `video` .`id` > (SELECT v.`id` FROM `video` v WHERE v.`id` < {$id} ORDER BY v.`id` DESC LIMIT 1) AND `video`.`lang` = '{$lang}'
        ORDER BY `video` .`id` ASC 
        LIMIT 3";
  
  $res = mysql_query($query);
  
  for($i=0; $row = mysql_fetch_array($res); $i++){
    $result[$i] = $row;
  }
  return $result;
}

A
Abay Tazhigaliev, 2016-02-08
@webcoderpro

In the video selection function, you need to add the $id? Then call him in the case, right?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question