douyun1860 2012-06-03 04:16
浏览 79

搜索结果的php分页无法显示

i've just been learning pagination. i'm having trouble getting it to work for search results. it displays the first page correctly with the right number of links but clicking on any of the links (even on the page 1) goes to a blank page.

can somebody please tell me what i'm doing wrong:

The following code is for when the search button is clicked.

<?php

include('includes/connect-db.php');
include('includes/functions.php');

if (isset($_GET['searchbtn'])){
    $product=$_GET['products'];
    $status=$_GET['ticket_status'];
    $order_by=$_GET['order_by'];
    $ticket_type=$_GET['ticket_type'];

    #check if product has been selected
    if ($_GET['products'] == 'select'){
        echo '<font class="error">&nbsp Please select a product to search.</font>'; 
    }else{
        if ($status == 'All' AND $order_by == 'All' AND $ticket_type == 'All' ){
            $page_query="SELECT * FROM tickets WHERE product='$product' ORDER BY created DESC";
        }elseif ($ticket_type == 'BOX'){
            $page_query="SELECT * FROM tickets WHERE product='$product' AND status='$status' AND pbi <> '-' ORDER BY '$order_by'    ";
        }elseif ($ticket_type == 'PVR'){
            $page_query="SELECT * FROM tickets WHERE product='$product' AND status='$status' AND inc <> '-' ORDER BY '$order_by'    ";
        }else{
            $page_query="SELECT * FROM tickets WHERE product='$product' AND status='$status' ORDER BY created DESC";
        }   
    }#end of else

    $results_per_page=3;
    $result_set=pagination($results_per_page,$page_query);

    $query=$result_set['query'];
    $pages=$result_set['pages'];

    #SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset. A resource on success or False on Error

    if (!empty($query)){
        $result = mysqli_query($db,$query) or die( "My query ($query) generated an error: ".mysql_error());
        $num_results = mysqli_num_rows($result);

        if ($num_results > 0){
            displayTicket($result);
            if ($pages > 1){
                echo '</br>';
                for($i=1;$i<=$pages;$i++){
                    echo ' <a href="?page='.$i.'">'.$i.'</a> ';
                }
            }
        }else{
            echo "&nbsp No Records found.";
        }
    }#query string is not empty
}   


?>

i have put the pagination code in a separate function:

function pagination($per_page, $pages_query){
    include('includes/connect-db.php');
    $pagination[]=array();

    #total result count 
    $total_result=mysqli_query($db,$pages_query);

    #ceil takes a decimal number and gives the nearest whole number
    $total=mysqli_num_rows($total_result);
    $pages = ceil($total / $per_page);

    $page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
    $start = ($page - 1) * $per_page;

    $query = " LIMIT $start,$per_page";
    $query = $pages_query.$query;
    $pagination['query'] = $query;
    $pagination['pages'] = $pages; 
    return $pagination;
}

Note: the pagination linking to other pages only fails when i attempt it with the search feature. i have tried it on a page that lists information in a table and the links work fine.

  • 写回答

2条回答 默认 最新

  • dongshanni1611 2012-06-03 04:51
    关注

    It looks to me like the problem is the information in the link: localhost/test/searchProductForm.php?page=1 tells searchProductForm which page to display, but it doesn't tell it what the search information was. Without that, your search page has no idea what to display. Try changing the pagination link to include all the information that was in the original search link (i.e., your products, ticket_status, order_by, and ticket_type parameters).

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用