javascript - How to use LIMIT and OFFSET for pagination in MYSQL? -


by code can able retrieve first 5 records database.

but need display remaining 5 rows database after pressing pagination arrow. doing 1 video sharing website same youtube.

  <?php include "config.php";   $q = mysql_query("select * register r                   join videos v on r.id = v.video_id                   order r.id limit 5") or die (mysql_error());  $headers = $col = ""; $row=mysql_num_rows($q); $s=null; echo "<h1> top videos </h1>"; while ($row = mysql_fetch_array($q))  { if($row['id']!=$s) { $s = $row['id'];  echo "<div class='property'>"; echo "<div class='property1' >"; echo "<a href='#'><video src=\"".$row['path']."\" height='100' width='170' style= margin:5px; controls='controls'></video></a>"; echo "</div>"; echo "<div class='property2'>"; echo $row['videoname']; echo "</div>"; echo "<div class='property3'>"; echo "<br/>"; echo "by:"; echo $row['name']; echo "<br/>"; echo "</div>"; echo "<div class='property4'>"; echo $row['views'].'&nbsp;&nbsp;views&nbsp;'; echo $row['time'].'&nbsp;&nbsp;year ago'; echo "</div>"; echo "</div>"; } } echo "<input type='button' class='btn1'>";  ?>  </div> 

prefer javascript,php,mysql

limit 5 takes first 5 rows results (position 0, 1, 2, 3 , 4 result set).

limit 5,5 takes 5 rows result set starts @ position 5. 'next' 5 results @ position 5, 6, 7, 8 , 9.

example: if result without limit like:

----------------- |  id  |  video | -------+--------- |  1   |  cat   | -------+--------- |  2   |  dog   | -------+--------- |  3   |  bird  | -------+--------- |  4   |  cow   | -------+--------- |  5   |  snake | -------+--------- |  6   |  fish  | -------+--------- |  7   |  mouse | -------+--------- |  8   |  shark | -------+--------- |  9   | seal   | -------+--------- |  10  | rabbit | ----------------- 

and use limit 5 or limit 5, 0

----------------- |  id  |  video | -------+--------- |  1   |  cat   | -------+--------- |  2   |  dog   | -------+--------- |  3   |  bird  | -------+--------- |  4   |  cow   | -------+--------- |  5   |  snake | -------+--------- 

and use limit 5, 5

----------------- |  id  |  video | -------+--------- |  6   |  fish  | -------+--------- |  7   |  mouse | -------+--------- |  8   |  shark | -------+--------- |  9   | seal   | -------+--------- |  10  | rabbit | ----------------- 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -