搜索结果无法显示分页

时间:2015-07-28 05:23:38

标签: php mysql pagination

我刚学习分页。我无法将其用于搜索结果。它使用正确数量的链接正确显示第一页,但点击任何链接(即使在第1页上)也会转到空白页。

有人可以告诉我我做错了什么:

以下代码适用于单击搜索按钮的时间。

<div class="twelve columns">
        <div class="search">
            <div class="searchbox">
                <div id="form-container"> 
                        <div id="searchtext">
                        <form name="formSearch" method="GET" action="view_referral.php" >
                        <button class="gobtn">Search</button>
                        <input type = "text" id="s" name="searchField" size="25" placeholder="Search referrals...">
                        <input type ="submit" name="searchButton" value="Search" style="display:none;">
                        </form>
                        </div>
                </div>
            </div>
        </div>
    </div>

我已将分页代码放在一个单独的函数中:     这是查看我的分页的链接。https://gist.github.com/markchristian27/4a3fbc3b34e9a78ccbcc

注意:当我尝试使用搜索功能时,链接到其他页面的分页失败。我在一个列出表中信息的页面上尝试过,链接工作正常。

<div class="referentprofile"> 
                            <p>List of Referrals</p>
                            <table class="u-full-width">
                                <tr>
                                <td><strong>Lead No.<strong></td>
                                <td><strong>Referral Name</strong></td>
                                <td><strong>Date Referred</strong></td>
                                <td><strong>Mobile Number</strong></td>
                                <td><strong>Email Address</strong></td>
                                <td><strong>Call Status</strong></td>
                                <td><strong>Application Status</strong></td>
                                </tr>
                            <?php

                        $_SESSION['SESS_PAGE'] = $_SERVER['PHP_SELF'];

                        // Change this during actual system run
                        if (empty($_GET['searchField'])){
                        include('../function/func_testPopulateLeads.php');
                                }
                                else {
                                    include('../function/func_testSearchByName.php');
                                    } 

                        ?>

                    </table>
                            </div>
                        <center>
                        <div style="text-align: center;">
                    <?php 
                    include('../function/func_pagination_new.php'); 
                    ?>
                    <?=$pagination?>
                </div>
                </center>   

分页和链接在include中工作正常(&#39; ../ function / func_testPopulateLeads.php&#39;);但是在include(&#39; ../ function / func_testSearchByName.php&#39;)中; ITS无法正常工作也许我认为问题在于链接中的信息:http://mainpage.com/refer/view_referral.php?searchField=mark告诉searchField要显示哪个页面,但它并没有告诉它搜索信息是什么是。没有它,您的搜索页面不知道要显示什么。

我试图将searchField的值连接到分页链接,但它仍然无法正常工作。例如,我在搜索框上输入mark。它的链接就像这个http://mainpage.com/refer/view_referral.php?searchField=mark

然后当我点击page 2时,它会更改为此http://mainpage.com/refer/view_referral.php?page=2 这肯定会保留mark的值,因为我的搜索页面在我转到下一页时不知道要显示什么。如何解决这个问题?请花时间阅读本文

1 个答案:

答案 0 :(得分:0)

您的代码中的主要问题是您使用链接进行分页,并且它不会将搜索字词作为参数传递。

$pagination.= "<a class='buttons' href=\"$targetpage?page=$next\">next</a>";

这将导致带有参数&#34; page = $ next&#34;的目标页面。每次更改页面时,都需要再次发送搜索项参数。

您可以将搜索字段存储在view_referral.php中,并检索分页php文件中的值。

例如:

首先,在view_referral.php中保存搜索值:

$_SESSION['searchField']=$_GET['searchField'];

然后,在分页php文件中,再次检索该值:

$pagination.= "<a class='buttons' href=\"$targetpage?page=".$next."&searchField=".$_SESSION['searchField']."\">next</a>";

这应该为你工作。

相关问题