FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


help with pagination problem





bartdou
Here are codes of a page(show.php) used to show guest's messages of a GuestBook, but there is a little problem: when click on the link to the 2nd,3th....pages, it doesn't work, the only change is the address changes to .../show.php?page=2(or 3,4...), the explorer still shows the 1st page which shows the last 2 msgs.
Help me please.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>show-msgs</title>
<style type="text/css">
body {font-family: Arial;font-size: 9pt}
table {font-family: Arial;font-size: 9pt}
a {text-decoration: none;color: 3366ff}
a:active {text-decoration: none}
a:hover {color: red;font-size: 9pt;text-decoration: underline}
</style>
</head>

<body bgcolor="#ffffff">
<p>My GuestBook<center><a href="">HomePage</a></center></p><a href="admin.php">Admin</a>

<?php
$sign=$HTTP_COOKIE_VARS["sign"]; //what use?
$dbhost="localhost";  //you know
$dbname="mydata";     //you know
$dbusername="root";   //you know
$dbpassword="";       //you know
$showrow=2;           //number of messages each page shows

function showpages($maxrow,$thispage){
        global $showrow; 
       
        if(($maxrow/$showrow)==Floor($maxrow/$showrow)){
                $n=Floor($maxrow/$showrow);
        }
        else{
                $n=Floor($maxrow/$showrow)+1;
        }

        if($n==1){
                echo"<p align='center'><a href=guestbook.php>leave msg</a></p>";
        }
        else{
                echo"<p align='left'>&gt;&gt;pagination";
                for($k=1;$k<$n+1;$k++){
                        if($k==$thispage){echo"[<b>$k</b>]";}
                        else{echo"[<b><a href='show.php?page=".$k."'>".$k."</a></b>]";}
                }
                echo"<a href=guestbook.php>leave msg</a></p>";
        }
}

function show_announce($id){
        global $db;
        global $board_id;  //???
        $query="SELECT * FROM guest WHERE id=$id";
        $result=mysql_query($query,$db);
        $myrow=mysql_fetch_array($result);
       
        echo"<table width=700 border=0 cellspacing=0 bordercolorright=#9999ff bordercorlordark=#ffffff>";
       
        echo"<tr bgcolor=#ddddff><td width=70><div align=right><font color=#3300cc><b>NAME:</b>";
        echo"</font></div></td><td>$myrow[name]</td></tr>";
       
        if($myrow[mail]<>""){
                echo"<tr><td width=70><div align=right><font color=#3300cc><b>E-mail:";
                echo"</b></font></div></td><td>$myrow[mail]</td></tr>";
        }
       
        if($myrow[host]<>""){
                echo"<tr><td width=70><div align=right><font color=#3300cc><b>Host:</b></font>";
                echo"</div></td><td><a href=$myrow[host] target=_blank>$myrow[host]</a></td></tr>";
        }
       
        echo"<tr><td width=70><div align=right><font color=#3300cc><b>TITLE:</b></font>";
        echo"</div></td><td>$myrow[title]($myrow[addtime])</td></tr>";
       
        echo"<tr><td width=70 valign=top><div align=right><font color=#3300cc><b>COMMENT:";
        echo:"</b></font></div></td><td>$myrow[text]</td></tr></table>";
       
        global $sign;
        if($sign=="dowebs"){                       //???
                echo"<a href=delete.php?id=$myrow[id]>dELETE</a>";
        }
        mysql_free_result($result);
}

if($page<2){$page=1;}                           //
echo $page;                                     //used for testing£¬$page=1 always.
$db=mysql_connect($dbhost,$dbusername,$dbpassword);
mysql_select_db($dbname,$db);
$offset=($page-1)*$showrow;
$query="SELECT id FROM guest ORDER BY id desc";//
$result_top=mysql_query($query,$db);
$num=mysql_num_rows($result_top);             
showpages($num,$page);                          //
$query="SELECT id FROM guest ORDER BY id desc LIMIT $offset,$showrow";
$result_top=mysql_query($query,$db);
while($myrow_top=mysql_fetch_array($result_top)){
        show_announce($myrow_top[id]);
}
showpages($num,$page);
mysql_close($db);
?>
</body>
</html>
hexkid
bartdou wrote:
.../show.php?page=2(or 3,4...), the explorer still shows the 1st page which shows the last 2 msgs.


REGISTER_GLOBALS !!!
When PHP gets a URL like http://www.example.com/show?page=7 it used to automatically create a variable named $page with the value 7. As of PHP 4.2.0 the default configuration changed and that does not happen.
You can reconfigure your browser to use register_globals (not recommended) or use the predefined SUPER GLOBAL ARRAYS instead.

In your code the variable $page is never initialized. Try adding this line right after the first <?php
Code:
$page = $_GET['page'];
Related topics
Frihost DC (Distributed Computing) Project
Very large problem[SOLVED]
[HELP] PC PROBLEM (don't bind)
How to turn a nice thought into a serious idea?
Ioncube loaders on server
IONCUBE DECODER PROBLEM
Please I need help in the serverq
Help! Installation Problem.
Please Help Packet Problem
recording on PC
BSOD
PHP noob problem
help for problem! how to do?
Still i have that ftp problem
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.