Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用while循环创建分页_Php_Html_While Loop_Pagination - Fatal编程技术网

Php 使用while循环创建分页

Php 使用while循环创建分页,php,html,while-loop,pagination,Php,Html,While Loop,Pagination,我想使用while循环创建分页。 我已经将数据限制为10。但我不知道如何在下面的时间计算中显示页码。 有什么解决办法吗? 多谢各位 <table border=0 width=800 cellspacing=1 cellpadding=2> <tr height=22> <td align=center bgColor=red width=5%>No.</td> <td align=center bgColor=red width

我想使用while循环创建分页。 我已经将数据限制为10。但我不知道如何在下面的时间计算中显示页码。 有什么解决办法吗? 多谢各位

<table border=0 width=800 cellspacing=1 cellpadding=2>
<tr height=22>
   <td align=center bgColor=red width=5%>No.</td>
   <td align=center bgColor=red width=15%>Date</td>
   <td align=center bgColor=red width=20%>Time</td>
   <td align=center bgColor=red width=15%>Status</td>
</tr>

<?php
    $start_hour = "05";
    $start_min = "00";
    $end_hour = "15";
    $end_min = "00";

    $start = new DateTime("$start_hour$start_min");
    $end = new DateTime("$end_hour$end_min");   
    $article_num = 1;
    $resultPerPage = 10;
    $pageNum = 1;

    while (($start < $end) && ($article_num <= $resultPerPage)) {
        $start_time = $start->format('H:i');
        $key_time = $start->format('Hi');
        $start->modify('+10 minute');
        $end_time = $start->format('H:i');

        $link_reserv = "#";

        echo ("<tr>");
        echo ("<td align=center>$article_num</td>");
        echo ("<td align=center>2013/12/16</td>");
        echo ("<td align=center>$start_time - $end_time</td>");
        echo ("<td align=center><input type=button value=Book&nbsp;Now onclick=\"window.location.href='$link_reserv';\"></td>");
        echo ("</tr>");

        $article_num++;
    }
?>
</table>

提示:pages=floortotal/recordsPerPage。只需获取总行数除以页面中要显示的记录数,$start<$end。。。我删除$article\u num
<?php
$conn=mysql_connect("localhost","root","");
$sdb=mysql_select_db("pagination",$conn);

$tableName="emp_details"; //page name
$targetpage = "pagination.php";
$limit = 3; //limit of dispaly

$query = "SELECT COUNT(*) as num FROM $tableName";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];

$stages = 3;
$page = mysql_escape_string($_GET['page']);
if($page){
$start = ($page - 1) * $limit;
}else{
$start = 0;
}

// Get page data
$sel = mysql_query("select * FROM $tableName LIMIT $start, $limit");
while($row1=mysql_fetch_array($sel))
{
$id=$row1['emp_id'];
$name=$row1['emp_name'];
$doj=$row1['doj'];
$experince=$row1['experince'];
$salary=$row1['salary'];
?>
<tr >
<td height="20"><?php echo $id;?></td>
<td><?php echo $name; ?></td>
<td><?php echo $doj; ?></td>
<td><?php echo $experince ?>year</td>
<td><?php echo $salary ?></td>

</tr>
<?php } ?>
<tr><td colspan="5" >
<?php

// Initial page num setup
if ($page == 0){$page = 1;}
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$LastPagem1 = $lastpage - 1;


$paginate = '';
if($lastpage > 1)
{

$paginate .= "<div class='paginate'>";
// Previous
if ($page > 1){
$paginate.= "<a href='$targetpage?page=$prev'>previous</a>";
}else{
$paginate.= "<span class='disabled'>previous</span>"; }


// Pages
if ($lastpage < 7 + ($stages * 2)) // Not enough pages to breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
}
elseif($lastpage > 5 + ($stages * 2)) // Enough pages to hide a few?
{
// Beginning only hide later pages
if($page < 1 + ($stages * 2))
{
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";
}
// Middle hide some front and some back
elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
{
$paginate.= "<a href='$targetpage?page=1'>1</a>";
$paginate.= "<a href='$targetpage?page=2'>2</a>";
$paginate.= "...";
for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";
}
// End only hide early pages
else
{
$paginate.= "<a href='$targetpage?page=1'>1</a>";
$paginate.= "<a href='$targetpage?page=2'>2</a>";
$paginate.= "...";
for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
}
}

// Next
if ($page < $counter - 1){
$paginate.= "<a href='$targetpage?page=$next'>next</a>";
}else{
$paginate.= "<span class='disabled'>next</span>";
}

$paginate.= "</div>";


}
echo $total_pages.' Results';
// pagination
echo $paginate;
?></td></tr>
</table>