Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.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,我正在构建一个搜索页面,用户可以通过一个字段进行搜索,然后显示表格。我试图通过php在其中实现分页,但分页不起作用。任何分页指南都会很有帮助。如果用户输入了第一个字段,而其他字段留空,我将给出其中一个字段的代码,还有其他条件 if($item!="" && $brand=="" && $model=="") { $sql ="SELECT * FROM table WHERE Product LIKE '%".$item."%' "; $resul

我正在构建一个搜索页面,用户可以通过一个字段进行搜索,然后显示表格。我试图通过php在其中实现分页,但分页不起作用。任何分页指南都会很有帮助。如果用户输入了第一个字段,而其他字段留空,我将给出其中一个字段的代码,还有其他条件

if($item!="" && $brand=="" && $model=="") {
    $sql ="SELECT * FROM table WHERE Product LIKE '%".$item."%' ";
    $result = mysql_query($sql);
    //$result1 = mysql_query($sql1);
    $r = mysql_fetch_array($result);
    $p=$r['Product'];
    $b=$r['Brand'];
    $m=$r['Model'];
    if ($item!=$p) {
        echo "<font style=\"color:Red;\"><h3>No Item Found!!!</h3></font>";
    } else  {
        echo "<table class='table table-striped table-bordered bootstrap-datatable datatable'>
            <thead>
            <tr>
            <th>Item</th>
            <th>Brand</th>
            <th>Model</th>
            <th>Dealer Price</th>
            <th>Quantity</th>
            <th>Description</th>
            </tr>
            </thead>";

        if (!(isset($pagenum)))  { 
            $pagenum = 1; 
        } 
        //Here we count the number of results 
        //Edit $data to be your query 
        $data = mysql_query("SELECT * FROM table WHERE Product='$item' ") or die(mysql_error()); 
        $rows = mysql_num_rows($data); 
        //This is the number of results displayed per page 
        $page_rows = 10; 
        //This tells us the page number of our last page 
        $last = ceil($rows/$page_rows); 
        //this makes sure the page number isn't below one, or more than our maximum pages 
        if ($pagenum < 1) { 
            $pagenum = 1; 
        } elseif ($pagenum > $last) { 
            $pagenum = $last; 
        } 
        //This sets the range to display in our query 
        $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; 
        $sqll ="SELECT * FROM table WHERE Product='$item'  $max ";
        $resultt = mysql_query($sqll);
        echo "<tbody>";
        while($row = mysql_fetch_array($resultt)) {
            echo "<tr>";
            echo "<td>" . $row['Product'] . "</td>";
            echo "<td>" . $row['Brand'] . "</td>";
            echo "<td>" . $row['Model'] . "</td>";
            echo "<td>" . $row['Dprice'] . "</td>";
            echo "<td>" . $row['Quantity'] . "</td>";
            echo "<td>" . $row['Quality'] . "</td>";
            echo "</tr>";
        }
        echo "</tbody>";
        echo "</table>";
        echo " --Page $pagenum of $last-- <p>";
        // First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page.
        if ($pagenum == 1) {
        } else {
            echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> ";
            echo " ";
            $previous = $pagenum-1;
            echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> ";
        } 
        //just a spacer
        echo " ---- ";
        //This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
        if ($pagenum == $last) {
        } else {
            $next = $pagenum+1;
            echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> ";
            echo " ";
            echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> ";
        } 
    } elseif($item=="" && $brand!="" && $model=="") {
……等等


我已尝试对表进行分页,第一页中有10行可见,但在进入下一页时,没有显示任何表,尽管表中还有其他数据。

错误在于必须在第一个文件的顶部添加

$pagenum = filter_input(INPUT_GET, 'pagenum', FILTER_SANITIZE_NUMBER_INT);
如果不从$\u GET param为$pagenum赋值,则无法直接访问$pagenum


我希望这是有用的

您应该在文件的顶部添加此代码。示例:如果$item!=&$brand==&&$model=={我已经添加了这个,但问题仍然存在。它仍然没有显示任何内容?或者您有一些错误?没有错误,相同的问题仍然存在,单击下一页时没有显示任何表。请尝试输出此变量:$last,$rows