使用现有的CODE将分页添加到PHP网站

时间:2014-11-11 22:02:19

标签: php list twitter-bootstrap mysqli

这是我显示视频列表的代码:

<?php

$result = mysqli_query($con,$query);
echo "<div class=\"maincover \" data-role=\"scrollbox\" data-scroll=\"vertical\">";

echo "<div class=\"panel panel-default\">";
while($row = mysqli_fetch_array($result)) {
echo "<div class=\"panel-heading\">";
echo '<div><a class="panel-title btn-block" href="details.php?id='.$row['id'].'"><h3>'.$row['id'].' | '.$row['vidTitle'].'</h3></a></div>';
echo "</div>";

echo "<div class=\"panel-body\">";
echo "<div class=\"imgCover\"><img class=\"imageCover\"src=\"" . $row['url'] . "\"></div>";
echo "<div class=\"vidSD\">" . $row['vidSD'] . "</div>";
echo "<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>";

echo " <div class=\"panel-footer\">";
echo '<h6><strong>' . $lang['vsdAuthor'] . '</strong><a href="../userPages/user.php?u='.$row['addName'].'">'.$row['addName'].'</a></h6>';
echo '<div><h6><strong>' . $lang['vsdPublished'] . '</strong>' . $row['published'] . '</h6></div>'; 
echo "</div>";
}
echo "</div></div>";

mysqli_close($con);
?>

我需要在底部,如果我有超过10个结果,它会显示如下按钮 CLICK

基本上像谷歌使用的页面数量从1到10,如果你打开第10页,它将显示5到15之间的页面。


这是我想要的另一个示例 CLICK 但我不确定如何在我的代码中实现此功能......

1 个答案:

答案 0 :(得分:1)

首先,这只能用bootstrap来完成,因为它是前端框架。 为此,您还必须使用服务器端分页,或使用JS。

这是教程

的链接

http://www.techumber.com/2012/08/simple-pagination-with-php-mysql.html

<强>的index.php

include ('paginate.php'); //include of paginat page
$per_page = 5;         // number of results to show per page
$result = mysql_query("SELECT * FROM countries");
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results / $per_page);//total pages we going to have
//-------------if page is setcheck------------------//
if (isset($_GET['page'])) {
    $show_page = $_GET['page']; //current page
    if ($show_page > 0 && $show_page <= $total_pages) {
        $start = ($show_page - 1) * $per_page;
        $end = $start + $per_page;
    } else {
        // error - show first set of results
        $start = 0;              
        $end = $per_page;
    }
} else {
    // if page isn't set, show first set of results
    $start = 0;
    $end = $per_page;
}
// display pagination
$page = intval($_GET['page']);
$tpages=$total_pages;
if ($page <= 0)
    $page = 1;