Php 注意:用于搜索和分页的未定义变量(自定义帖子类型)

Php 注意:用于搜索和分页的未定义变量(自定义帖子类型),php,Php,我有一些错误,我不能解决这个问题。你能帮帮我吗? 这是因为您使用的是不推荐使用的函数? 我该如何解决这个问题 这是密码 <?php class Pagination { function getStartRow($page,$limit){ $startrow = $page * $limit - ($limit); return $startrow; } function showPageNumbers($totalrows

我有一些错误,我不能解决这个问题。你能帮帮我吗? 这是因为您使用的是不推荐使用的函数? 我该如何解决这个问题

这是密码

<?php

class Pagination {
    function getStartRow($page,$limit){
        $startrow = $page * $limit - ($limit);
        return $startrow;
    }   
    function showPageNumbers($totalrows,$page,$limit){

        $query_string = $this->queryString();

        $pagination_links = null;

        /*
        PAGINATION SCRIPT
        seperates the list into pages
        */      
         $numofpages = $totalrows / $limit; 
        /* We divide our total amount of rows (for example 102) by the limit (25). This 

    will yield 4.08, which we can round down to 4. In the next few lines, we'll 
    create 4 pages, and then check to see if we have extra rows remaining for a 5th 
    page. */

        for($i = 1; $i <= $numofpages; $i++){
        /* This for loop will add 1 to $i at the end of each pass until $i is greater 
    than $numofpages (4.08). */     

          if($i == $page){
                $pagination_links .= '<div class="page-link"><span>'.$i.'</span></div> ';
            }else{ 
                $pagination_links .= '<div class="page-link"><a href="?page='.$i.'&'.$query_string.'">'.$i.'</a></div> '; 
            }
            /* This if statement will not make the current page number available in 
    link form. It will, however, make all other pages available in link form. */
        }   // This ends the for loop

        if(($totalrows % $limit) != 0){
        /* The above statement is the key to knowing if there are remainders, and it's 
        all because of the %. In PHP, C++, and other languages, the % is known as a 
        Modulus. It returns the remainder after dividing two numbers. If there is no 
        remainder, it returns zero. In our example, it will return 0.8 */

            if($i == $page){
                $pagination_links .= '<div class="page-link"><span>'.$i.'</span></div> ';
            }else{
                $pagination_links .= '<div class="page-link"><a href="?page='.$i.'&'.$query_string.'">'.$i.'</a></div> ';
            }
            /* This is the exact statement that turns pages into link form that is used above */ 
        }   // Ends the if statement 

        return $pagination_links;
    }

    //added by drale.com - 1-19-2010
    function showNext($totalrows,$page,$limit,$text="next &raquo;"){    
        $next_link = null;
        $numofpages = $totalrows / $limit;

        if($page < $numofpages){
            $page++;
            $next_link = '<div class="page-link"><a href="?page='.$page.'&'.$query_string.'">'.$text.'</a></div>';
        }

        return $next_link;
    }

    function showPrev($totalrows,$page,$limit,$text="&laquo; prev"){    
        $next_link = null;
        $numofpages = $totalrows / $limit;

        if($page > 1){
            $page--;
            $prev_link = '<div class="page-link"><a href="?page='.$page.'&'.$query_string.'">'.$text.'</a></div>';
        }

        return $prev_link;
    }

    function queryString(){ 
        //matches up to 10 digits in page number
        $query_string = eregi_replace("page=[0-9]{0,10}&","",$_SERVER['QUERY_STRING']);
        return $query_string;
    }
} 
?>

是因为您已将PHP版本升级到5.3?

这是因为您使用了一个不推荐使用的函数eregi_replace作为错误状态

从PHP5.3.0开始,eregi_replace就不推荐使用。建议使用i PCRE_无壳修改器替换preg_

使用函数来解决问题

已弃用:C:\xampp\htdocs\manager\Pagination.php第86行的函数eregi_replace已弃用

您希望改为如下使用:

$query_string = preg_replace("page=[0-9]{0,10}&","",$_SERVER['QUERY_STRING']);
注意:未定义变量:第81行C:\xampp\htdocs\manager\Pagination.php中的prev_链接

之所以会发生这种情况,是因为没有真正为返回定义prev_link,所以请将代码更改为:

$prev_link = null;
if($page > 1){
    $page--;
    $prev_link = '<div class="page-link"><a href="?page='.$page.'&'.$query_string.'">'.$text.'</a></div>';
}

return $prev_link;
注意:未定义的变量:C:\xampp\htdocs\manager\Pagination.php第66行的query_字符串

这是因为函数showPrev中没有定义变量$query\u字符串。我不知道你想从哪里得到它,但是你要么把它作为一个参数发送进来,要么从某处收集它


现在,来谈谈你收到的反对票。像这样的问题表明没有努力。虽然您可能已经做了一些工作,但您没有记录下来,所以我们可以告诉您,您只是希望我们为您进行调试。您提供了所有的代码,这很好,但请记住,展示您已经付出了哪些努力。

出现错误的原因是因为以下代码:

    if($page > 1){
        $page--;
        $prev_link = '<div class="page-link"><a href="?page='.$page.'&'.$query_string.'">'.$text.'</a></div>';
    }

    return $prev_link;
这将确保无论页码如何,都已初始化变量

$query\u字符串错误完全相同,但在程序中的其他位置。希望您能够通过修改上面的帮助来解决这个问题

最后,ereg错误是因为您已将PHP版本升级到5.3,但代码最初是为较早的PHP版本开发的。自PHP 5.3以来,不再支持ereg函数和所有相关函数,应使用preg_match、preg_replace等替换。此处有许多问题可以帮助您解决此问题-例如,尝试以下问题:


希望对您有所帮助。

首先注意:您应该切换到preg\u replace

第二个通知:$prev_link是在一个有条件的情况下初始化的,删除这些通知的最简单的解决方案是$prev_link=;在showPrev函数中的if语句之前


第三个注意事项:$query\u字符串未在showNext范围内的任何位置定义

如弃用通知所述,ereg功能不再受支持。你应该用preg_match替换它。搜索此网站以获取如何执行此操作的示例;很容易,错误是自解释的preg\u replace我会收到其他错误我会收到preg\u replace的其他错误:警告:preg\u replace[function.preg replace]:C:\xampp\htdocs\manager\Pagination.php第行中的分隔符不能是字母数字或反斜杠83@razvan-阅读我在答案末尾链接的问题-它有这个问题的解决方案。如果这不起作用,那么网上还有数百篇其他帖子也在问同样的问题。感谢大家,我解决了这个问题
$prev_link = '';