Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.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 标页码为什么只显示一页?_Php_Mysql_Pagination - Fatal编程技术网

Php 标页码为什么只显示一页?

Php 标页码为什么只显示一页?,php,mysql,pagination,Php,Mysql,Pagination,我一直试图让分页工作,我有一定程度上,但它只显示一页的结果 我的数据库中有18个列表,并将其设置为每页显示6个 有人知道问题出在哪里吗 <?php include('includes/configsql.php'); //include header template include('layout/header.php'); //include navbar template include('layout/navbar.php'); ?> <?php $co

我一直试图让分页工作,我有一定程度上,但它只显示一页的结果

我的数据库中有18个列表,并将其设置为每页显示6个

有人知道问题出在哪里吗

<?php include('includes/configsql.php'); 

//include header template
include('layout/header.php'); 

//include navbar template
include('layout/navbar.php'); 


?>

<?php
$con = mysqli_connect($db_hostname,$db_username,$db_password,$db_database);

$sql = "SELECT COUNT(id) FROM basic WHERE status='active'";
$query = mysqli_query($con, $sql);
$row = mysqli_fetch_row($query);

$rows = $row[0];
$rows = mysqli_num_rows($query);

$page_rows = 6;
$last = ceil($rows/$page_rows);

if($last < 1){
    $last = 1;
}

$pagenum = 1;

if(isset($_GET['pn'])){
    $pagenum = preg_replace('#[^0-9]#', '', $_GET['pn']);
}

if ($pagenum < 1) { 
    $pagenum = 1; 
} else if ($pagenum > $last) { 
    $pagenum = $last; 
}

$limit = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$sql = "SELECT id, name, address, telephone, email, category FROM basic WHERE status='active' ORDER BY name ASC $limit";
$query = mysqli_query($con, $sql);

$textline1 = "Basic Listing (<b>$rows</b>)";
$textline2 = "Page <b>$pagenum</b> of <b>$last</b>";

$paginationCtrls = '';
if($last != 1){
    if ($pagenum > 1) {
        $previous = $pagenum - 1;
        $paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?pn='.$previous.'">Previous</a> &nbsp; &nbsp; ';
        for($i = $pagenum-4; $i < $pagenum; $i++){
            if($i > 0){
                $paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a> &nbsp; ';
            }
        }
    }

    $paginationCtrls .= ''.$pagenum.' &nbsp; ';
    for($i = $pagenum+1; $i <= $last; $i++){
        $paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a> &nbsp; ';
        if($i >= $pagenum+4){
            break;
        }
    }
    if ($pagenum != $last) {
        $next = $pagenum + 1;
        $paginationCtrls .= ' &nbsp; &nbsp; <a href="'.$_SERVER['PHP_SELF'].'?pn='.$next.'">Next</a> ';
    }
}
$list = '';
while($row = mysqli_fetch_array($query)){
    $id = $row["id"];
    $name = $row["name"];
    $category = $row["category"];
    $list .= '<p><a href="business.php?id='.$id.'">'.$name.' &nbsp;|&nbsp;'.$category.' </a> - Click the link to view this business</p>';
}

mysqli_close($con);
?>


<div id="wrapper">


<div id="bizlist">

 <div id="pagination">
  <h2><?php echo $textline1; ?></h2>
  <p><?php echo $textline2; ?></p>
  <p><?php echo $list; ?></p>
  <div id="pagination_controls"><?php echo $paginationCtrls; ?></div>
</div>

</div>



<?php 
//include footer template
include('layout/footer.php'); 
?>

我认为您必须删除该行:

 $rows = mysqli_num_rows($query);
这是在脚本的开头

另一种方法是修改第一行,如下所示:

$sql = "SELECT * FROM basic WHERE status='active'";
并删除接下来的3行

$query = mysqli_query($con, $sql);
$row = mysqli_fetch_row($query);
$rows = $row[0];

您必须选择上述其中一项,但不能同时选择两项:

非常感谢。。。。删除下面的第一行技巧:$rows=mysqli\u num\u rows$query;再次感谢。。。。非常感谢。