分页不完全正常

时间:2014-05-13 17:33:13

标签: php pagination

我在编写分页时遇到问题,虽然没有显示错误消息仍然无效。

我怀疑我必须要对这段代码做些什么。请帮帮我。 TIA家伙。

while($runrows=mysql_fetch_assoc($run, $limit))

以下是页面的代码

<?php

$connect = mysql_connect($m_Host,$m_User,$m_Pass) or die(mysql_error());
echo "<br />";

mysql_select_db($m_Db,$connect) or die(mysql_error());
error_reporting(error_reporting()&~E_NOTICE);

if(isset($_POST['search_query']))
{
$search_query=mysql_real_escape_string(htmlentities($_POST['search_query']));
echo "<div class=\"searchText\"><br><b class='float'>Search the knowledgebase</b></div><br><hr />";

$search_query_x=explode(" ",$search_query);

    foreach($search_query_x as $search_each)
        {
            $x++;
            if($x==1)
            $construct.="Tags LIKE '%$search_each%'";
            else
            $construct.="AND Tags LIKE '%$search_each%'";
        }
$construct="SELECT * FROM knowledgebase WHERE $construct";
$run=mysql_query($construct);
$foundnum=mysql_num_rows($run);

    if($foundnum==0)
        {
            echo "Sorry, there is no matching result for your query: <i><b>$search_query</b></i><br /><br />
            1. Please check your spelling.<br />
            2. Try more general terms.<br />
            3. Please check broader alternatives like Google.<br />
            4. Contact your <b>Floorwalker</b> or <b>Process Analyst</b>.<br />
            5. If you found the solution to this scenario somewhere else, please advise your <b>Knowledge Manager</b>.";
        }

    else
        {
            echo "$foundnum result(s) found!<p>";
                while($runrows=mysql_fetch_assoc($run, $limit))
                {
                $Document_Title=$runrows['Document Title'];
                $URL=$runrows['URL'];
                $Target_Account=$runrows['Target Account'];
                $Modified=$runrows['Modified'];
                $Tags=$runrows['Tags'];
                echo"

                <div class='width: 400px'>
                <div class='Document Title'><a href='$URL' title='$Document_Title &#013$Target_Account &#013 $Modified &#013$Tags' target='_blank'>$Document_Title</a></div>
                <div class='Target Account'>
                    <b><font face='arial' size='1' color='Black'>Program:</font></b>
                        <font face='arial' size='1' color='Black'>$Target_Account</font></div>
                <div class='Keywords'>
                    <b><font face='arial' size='1' color='Black'>Keywords:</font></b>
                        <font face='arial' size='1' color='Black'>$Tags</font></div>
                </div>
                <br />
                ";
                }
        }
}
        else
            {
            echo"Found what you were looking for? If not, please consult your Process Analyst.";
            }

    //to make pagination
        require_once('config.php');
        include_once ('php\function.php');
        $page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
        $limit = 5;
        $startpoint = ($page * $limit) - $limit;
        $statement = "`knowledgebase` where `active` = 1";
?>

<?php
        echo pagination($statement,$limit,$page);
?>

1 个答案:

答案 0 :(得分:1)

您需要更加具体地了解您的代码所做的事情 - 您声称没有错误消息,这是否意味着上述代码会产生空白页面?如果是这样,那很可能是由托管服务提供商的设置引起的,并且通常在解析和执行脚本期间发生任何错误时发生。尝试询问您的提供商是否可以启用错误报告,并确保查看是否存在您可以访问的错误日志文件。 很难为您提供所提供的信息,因为您向我们展示了许多看似无关的代码,同时隐藏了您遇到问题的源代码(分页功能)。你确定require_once和include_once函数没有错误吗?路径有效吗?

您可能还想使用内置的intval函数来解析$ _GET页面,而不是使用类型转换:

    $page = isset($_GET["page"]) ? intval($_GET["page"]) : 1;

我对您声称与您遇到的问题无关的代码部分也有一些疑问:我无法想象foreach循环产生有效的MySQL查询,因为您没有将LIKE分开彼此之间有空格。

$search_query_x=explode(" ",$search_query);

foreach($search_query_x as $search_each)
{
    $x++;

    if($x==1) {
         //           v          the search clauses need to be separated by spaces
         $construct.=" Tags LIKE '%$search_each%'";
    } else {
         //           v          same here
         $construct.=" AND Tags LIKE '%$search_each%'";
    }
}

$run=mysql_query($construct); // it's also important to check if the returned query resource ($run) is valid - mysql_query returns FALSE on failure
if ($run === false) {
    echo "MySQL query failed! Error #" . mysql_errno() . ": " . mysql_error();
    exit;
}

$foundnum=mysql_num_rows($run);