-2

你好,我是 php 新手,我遇到了这个错误

Notice: Undefined variable: page_pagination in K:\PHP WAMP\wamp\www\Oracle Certified Masters\Oracle Certified Masters\includes\middle.php on line 82

这是我的示例代码..请帮助我..

<?php


// how many rows to show per page
$rowsPerPage = 10;

// by default we show first page
$page_num = 1;

// if $_GET['page'] defined, use it as page number, $_GET gets the page number out of the url
//set by the $page_pagination below
if(isset($_GET['page'])){$page_num = $_GET['page'];}

//the point to start for the limit query
$offset = $page_num;
$page_pagination;
// Zero is an incorrect page, so switch the zero with 1, mainly because it will cause an error with the SQL
if($page_num == 0) {$page_num = 1;}

// counting the offset


$sql = "SELECT QUERY Limit $offset, $rowsPerPage ";
$res = mysql_query($sql) or die(mysql_error());

// how many rows we have in database
$sql2  = "SELECT COUNT(sub_ID) AS numrows FROM posts ";
$res2  = mysql_query($sql2) or die(mysql_error());
$row2  = mysql_fetch_array($res2);
$numrows = $row2['numrows'];

// print the random numbers
while($row = mysql_fetch_array($res))
{
    //Echo out your table contents here.

    echo $row[1].'<BR>';
    echo $row[2].'<BR>';
    echo '<BR>';
}

// how many pages we have when using paging?
$numofpages = ceil($numrows/$rowsPerPage);

// print the link to access each page
$self = "index.php?";

if ($numofpages > '1' ) {

    $range =15; //set this to what ever range you want to show in the pagination link
    $range_min = ($range % 2 == 0) ? ($range / 2) - 1 : ($range - 1) / 2;
    $range_max = ($range % 2 == 0) ? $range_min + 1 : $range_min;
    $page_min = $page_num- $range_min;
    $page_max = $page_num+ $range_max;

    $page_min = ($page_min < 1) ? 1 : $page_min;
    $page_max = ($page_max < ($page_min + $range - 1)) ? $page_min + $range - 1 : $page_max;
    if ($page_max > $numofpages) {
        $page_min = ($page_min > 1) ? $numofpages - $range + 1 : 1;
        $page_max = $numofpages;
    }

    $page_min = ($page_min < 1) ? 1 : $page_min;

    //$page_content .= '<p class="menuPage">';

    if ( ($page_num > ($range - $range_min)) && ($numofpages > $range) ) {
        $page_pagination .= '<a class="num"  title="First" href="'.$self.'page=1">&lt;</a> ';
    }

    if ($page_num != 1) {
        $page_pagination .= '<a class="num" href="'.$self.'page='.($page_num-1). '">Previous</a> ';
    }

    for ($i = $page_min;$i <= $page_max;$i++) {
        if ($i == $page_num)
        $page_pagination .= '<span class="num"><strong>' . $i . '</strong></span> ';
        else
        $page_pagination.= '<a class="num" href="'.$self.'page='.$i. '">'.$i.'</a> ';
    }

    if ($page_num < $numofpages) {
        $page_pagination.= ' <a class="num" href="'.$self.'page='.($page_num + 1) . '">Next</a>';
    }


    if (($page_num< ($numofpages - $range_max)) && ($numofpages > $range)) {
        $page_pagination .= ' <a class="num" title="Last" href="'.$self.'page='.$numofpages. '">&gt;</a> ';
    }

    //$page['PAGINATION'] ='<p id="pagination">'.$page_pagination.'</p>';
}//end if more than 1 page

echo $page_pagination.'<BR><BR>';

echo 'Number of results - '.$numrows ;
echo ' and Number of pages   - '.$numofpages.'<BR><BR>';

// Free resultset
//mysql_free_result($res);

// and close the database connection
//mysql_close($con);

?>
4

2 回答 2

1

简单$page_pagination;语句将此变量的值设置为null。但是当您.=稍后使用运算符时(或者,如果没有页面,echo则直接使用它),您需要将其设置为更实质的内容 - 同时为空。

一个空字符串非常适合这个类别:

$page_pagination = '';
于 2013-03-22T15:18:53.523 回答
0

这不是错误。这是一个通知。PHP 为您的代码提供不同级别的通知。通知、警告和错误。

通知意味着您的代码中有一些看起来不正确的东西。这不会停止代码执行

WARNING表示代码中的某些内容可能会给您带来错误。这不会停止代码执行

一个错误意味着,嗯,有一个错误。这将停止您的代码执行

就您收到的通知而言:很明显,您正在使用变量 $page_pagination,但之前没有定义它。

所以不仅仅是拥有

$page_pagination;

将其设置为:

$page_pagination = '';

有不同级别的通知、警告和错误可帮助您识别其来源。您可以在此答案顶部的链接上找到它们。

于 2013-03-22T15:22:44.257 回答