开发者

PHP pagination does not recognize $page

开发者 https://www.devze.com 2023-04-02 16:48 出处:网络
I have downloaded the pagination code and used it for my website running on my local machine. After modifying and testing, there was a problem where it does not recognize the variable $page.

I have downloaded the pagination code and used it for my website running on my local machine. After modifying and testing, there was a problem where it does not recognize the variable $page.

Please refer to the following code:

<?php
    $rpp = 3; // results per page
    $adjacents = 4;
    $page = intval($_GET["page"]);
    if($page<=0) $page = 1;
    $reload = $_SERVER['PHP_SELF'];
    $sql = "SELECT * FROM ".TABLE_IMAGE." ORDER BY id ASC";
    $qry = mysql_query($sql, $con);
    // count total number of appropriate listings:
    $tcount = mysql_num_rows($qry);

    // count number of pages:
    $tpages = ($tcount) ? ceil($tcount/$rpp) : 1; // total pages, last page number

    $i = 1;
    $count = 0;
    $j = ($page-1)*$rpp;
    while(($result = mysql_fetch_array($qry)) && (($count<$rpp) && ($j<$tcount))){
        $id = $result['id'];
        $img = $result['path'];
        $title = $result['title'];
        $detail = $result['detail'];
        $priority = $result['priority'];
        $active = $result['isActive'];
 ?>
<div id="block-image-slider"  class="<?php echo(($i%2==0)?'even':'odd')?>">
    <h2><?php echo $title ?></h2><span class="operation">[<a href="?action=edit&section=slider&id=<?php echo $id ?>">កែប្រែ</a>|<a href="?action=delete&section=slider&id='<?php echo $id ?>'">លុប</a>]</span>
    <div class="block-slider-image-body">
        <div class="left">
            <ul>
                <li>លេខរៀងទី<span class="space"><?php echo $id ?></span></li>
                <li>កំនត់អទិភាពទី<span class="space"><?php echo $priority ?></span></li>
                <li>ត្រូវបានបង្ហាញអោយឃើញ<span class="space"><?php echo (($active==1)?'បង្ហាញ':'មិនបង្ហាញ')?></span></li>
                <li>អត្ថបទពេញ<div class="detail"><?php echo $detail ?></div></li>
            </ul>
        </div>
        <div class="right">
            <img src="<?php echo '../../image/Slider/'.$img ?>" alt="<?php echo $title ?>" width="170" height="100" />
        </div>
        <div style="clear:both;"></div>
  </div>
</div>
<?php
        mysql_data_seek($qry,$j);

        $i++;
        $j++;
        $count++;
}//end of while loop

include("../include/paginate.php");
echo paginate_three($reload, $page, $tpages, $adjacents);
?>

This is the error it generated:

Notice: Undefined index: page in C:\wamp\www\1. Chirst Joy Church Website\common\adm开发者_如何学JAVAin\index.php on line 87

How can I fix this error?


This won't work unless your URL ends with ?page=3 (where 3 would be the current page number). In order to fix it you should change this line

$page = intval($_GET["page"]);

to

$page = (!empty($_GET["page"]) ? intval($_GET["page"]) : 1);
0

精彩评论

暂无评论...
验证码 换一张
取 消