database - Pagination, LIMIT do not work. PHP/MySqli -
this code:
<?php $sqlpages = 'select count(id) newsvid approved=1'; $querypages = mysqli_query($con, $sqlpages); $row = mysqli_fetch_row($querypages); // here have total row count $rows = $row[0]; // number of results want displayed per page $page_rows = 1; // tells page number of our last page $last = ceil($rows/$page_rows); // makes sure $last cannot less 1 if($last < 1){ $last = 1; } // establish $pagenum variable $pagenum = 1; // pagenum url vars if present, else = 1 if(isset($_get['pn'])){ $pagenum = preg_replace('#[^0-9]#', '', $_get['pn']); } // makes sure page number isn't below 1, or more our $last page if ($pagenum < 1) { $pagenum = 1; } else if ($pagenum > $last) { $pagenum = $last; } // sets range of rows query chosen $pagenum $limit = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; // query again, grabbing 1 page worth of rows applying $limit $querymain ="select newsvid.id, newsvid.addname, newsvid.vidtitle, newsvid.vidtype, newsvid.size, newsvid.url, newsvid.vidsd, newsvid.published, videoinformation.vidld, videoinformation.vidyear, videoinformation.vidcity, videoinformation.vidzanr, videoinformation.vidzanr2, videoinformation.vidzanr3, videoinformation.vidquality, videoinformation.vidtranslated, videoinformation.vidtime newsvid, videoinformation newsvid.id = videoinformation.id , approved=1 order desc $limit"; $resultdisplay = mysqli_query($con, $querymain); // shows user page on, , total number of pages $pagestitle = "on website <b>$rows</b>"; $pagesoutof = "page <b>$pagenum</b> of <b>$last</b>"; // establish $paginationctrls variable $paginationctrls = ''; // if there more 1 page worth of results if($last != 1){ /* first check if on page one. if don't need link previous page or first page nothing. if aren't generate links first page, , previous page. */ if ($pagenum > 1) { $previous = $pagenum - 1; $paginationctrls .= '<a href="'.$_server['php_self'].'?pn='.$previous.'">previous</a> '; // render clickable number links should appear on left of target page number for($i = $pagenum-4; $i < $pagenum; $i++){ if($i > 0){ $paginationctrls .= '<a href="'.$_server['php_self'].'?pn='.$i.'">'.$i.'</a> '; } } } // render target page number, without being link $paginationctrls .= ''.$pagenum.' '; // render clickable number links should appear on right of target page number for($i = $pagenum+1; $i <= $last; $i++){ $paginationctrls .= '<a href="'.$_server['php_self'].'?pn='.$i.'">'.$i.'</a> '; if($i >= $pagenum+4){ break; } } // same above, checking if on last page, , generating "next" if ($pagenum != $last) { $next = $pagenum + 1; $paginationctrls .= ' <a href="'.$_server['php_self'].'?pn='.$next.'">next</a> '; } } $list = ""; while($row = mysqli_fetch_array($resultdisplay, mysqli_assoc)){ $list .= "<div class=\"panel-heading\"> <div><a class=\"panel-title btn-block\" href=\"details.php?id=".$row['id']."\"><h3>".$row['id']." | ".$row['vidtitle']."</h3></a></div> </div> <div class=\"panel-body\"> <div class=\"imgcover\"><img class=\"imagecover\"src=\"" . $row['url'] . "\"></div> <div class=\"vidsd\">" . $row['vidsd'] . "</div> <div class=\"viddetails\"> <hr class=\"style-two\"> <table> <tr><td class=\"viddetailstd\"><strong>" . $lang['vtyear'] . "</strong></td><td class=\"viddetailstd\">" . $row['vidyear'] ."</td></tr> <tr><td class=\"viddetailstd\"><strong>" . $lang['vtcity'] . "</strong></td><td class=\"viddetailstd\">". $row['vidcity'] ."</td></tr> <tr><td class=\"viddetailstd\"><strong>" . $lang['vtgenre'] . "</strong></td><td class=\"viddetailstd\">". $row['vidzanr'] ." , ". $row['vidzanr2'] ." , ". $row['vidzanr3'] . "</td></tr> <tr><td class=\"viddetailstd\"><strong>" . $lang['vtquality'] . "</strong></td><td class=\"viddetailstd\">". $row['vidquality'] ."</td></tr> <tr><td class=\"viddetailstd\"><strong>" . $lang['vttranslatedby'] . "</strong></td><td class=\"viddetailstd\">". $row['vidtranslated'] ."</td></tr> <tr><td class=\"viddetailstd\"><strong>" . $lang['vtvideotime'] . "</strong></td><td class=\"viddetailstd\">". $row['vidtime'] . "</td></tr> </table> </div></div> <div class=\"panel-footer\"> <h6><strong>" . $lang['vsdauthor'] . "</strong><a href=\"../userpages/user.php?u=".$row['addname']."\">".$row['addname']."</a></h6> <div><h6><strong>" . $lang['vsdpublished'] . "</strong>" . $row['published'] . "</h6></div> </div>"; } include_once 'inc/sortorder.php'; mysqli_close($con); ?>
the problem working fine but instead of display 1 result on each page, displays everything.
when press different pages works (i mean pages changes (visually), , on page i'm changes well. but list display all result.
p.s. code sample not my, adapt it. think problem limit , code looks right me.
$querymain ="select newsvid.id, newsvid.addname, newsvid.vidtitle, newsvid.vidtype, newsvid.size, newsvid.url, newsvid.vidsd, newsvid.published, videoinformation.vidld, videoinformation.vidyear, videoinformation.vidcity, videoinformation.vidzanr, videoinformation.vidzanr2, videoinformation.vidzanr3, videoinformation.vidquality, videoinformation.vidtranslated, videoinformation.vidtime newsvid, videoinformation newsvid.id = videoinformation.id , approved='1'";
how can add limit??? queryone = querymain + $limit;
???
Comments
Post a Comment