Problem with displaying the data in several pages....
Posted: Fri Feb 14, 2003 2:48 pm
Hello, everyone,
I have struggled this problem for two days. I do really have no idea how to fix it. I tried to retrieve the data from database and display the data 3 rows per table. However, the links, [NEXT] and [Bottom] for going to next page, didn’t work. It always showed first page with 3 rows of data.
I copy my code here, a little long. But… pleaseeeeeeeeee help me out..
------------------ userviewer.php-----------------
<?php
include "common_db.inc";
function list_records() {
global $default_dbname,$user_tablename;
global $default_sort_order, $default_order_by, $records_per_page;
global $sort_order, $order_by, $cur_page;
$link_id=db_connect($default_dbname);
if(!$link_id) echo "cannot link to database";
$query="Select count(*) from $user_tablename";
$result=mysql_query($query);
if(!$result) echo "cannot execute the query";
$query_data=mysql_fetch_row($result);
$total_num_user=$query_data[0];
if(!$total_num_user) echo "no user found";
$page_num=$cur_page+1;
$total_num_page=$last_page_num=ceil($total_num_user/ $records_per_page);
echo "<html><body>";
echo "<center><h3>$total_num_user users found. Displaying the page $page_num out of $last_page_num.";
$limit_str="LIMIT " . $cur_page * $records_per_page . ",$records_per_page";
$query="select ID, District, Project_title from $user_tablename $limit_str";
$result=mysql_query($query);
if(!$result) echo "cannot execute query1";
?>
<DIV align="center">
<table border=1>
<tr>
<th width=25% NOWRAP><a href="<?php echo $_SERVER['PHP_SELF']."?action=list_records"; ?>">
ID</a></th>
<th width=25% NOWRAP><a href="<?php echo $_SERVER['PHP_SELF']."?action=list_records"; ?>">
District</a></th>
<th width=25% NOWRAP><a href="<?php echo $_SERVER['PHP_SELF']."?action=list_records"; ?>">
Project_title</a></th>
<th width=25% NOWRAP>test</th>
</tr>
<?php
while ($query_data=mysql_fetch_array($result)){
$ID=$query_data["ID"];
$District=$query_data["District"];
$Project_title=$query_data["Project_title"];
echo "<tr>\n";
echo "<td>$ID</td>\n";
echo "<td>$District</td>\n";
echo "<td>$Project_title</td>\n";
echo "<td>.. keep for future </td>";
echo "</tr>\n";
}
?>
</table>
</DIV>
<?php
echo "<br>\n";
echo "<strong><center>";
echo "page_num: $page_num <br>";
echo "cur_page: $cur_page <br>";
if($page_num>1){
$prev_page=$cur_page-1;
echo "<a href=\"{$_SERVER['PHP_SELF']}?action=list_records&cur_page=0\">[top]</a>";
echo "<a href=\"{$_SERVER['PHP_SELF']}?action=list_records&cur_page=$prev_page\">[prev]</a>";
}
if($page_num<$total_num_page){
$next_page=$cur_page + 1;
$last_page=$total_num_page - 1;
echo "<a href=\"{$_SERVER['PHP_SELF']}?action=list_records&cur_page=$next_page\">[next]</a>";
echo "<a href=\"{$_SERVER['PHP_SELF']}?action=list_records&cur_page=$last_page_num\">[bottom]</a>";
}
echo "</strong></center>";
html_footer();
}
switch ($_GET['action']){
case "view_record";
break;
default:
list_records();
break;
}
?>
-----------------------
Thank you..
Winter

I have struggled this problem for two days. I do really have no idea how to fix it. I tried to retrieve the data from database and display the data 3 rows per table. However, the links, [NEXT] and [Bottom] for going to next page, didn’t work. It always showed first page with 3 rows of data.
I copy my code here, a little long. But… pleaseeeeeeeeee help me out..
------------------ userviewer.php-----------------
<?php
include "common_db.inc";
function list_records() {
global $default_dbname,$user_tablename;
global $default_sort_order, $default_order_by, $records_per_page;
global $sort_order, $order_by, $cur_page;
$link_id=db_connect($default_dbname);
if(!$link_id) echo "cannot link to database";
$query="Select count(*) from $user_tablename";
$result=mysql_query($query);
if(!$result) echo "cannot execute the query";
$query_data=mysql_fetch_row($result);
$total_num_user=$query_data[0];
if(!$total_num_user) echo "no user found";
$page_num=$cur_page+1;
$total_num_page=$last_page_num=ceil($total_num_user/ $records_per_page);
echo "<html><body>";
echo "<center><h3>$total_num_user users found. Displaying the page $page_num out of $last_page_num.";
$limit_str="LIMIT " . $cur_page * $records_per_page . ",$records_per_page";
$query="select ID, District, Project_title from $user_tablename $limit_str";
$result=mysql_query($query);
if(!$result) echo "cannot execute query1";
?>
<DIV align="center">
<table border=1>
<tr>
<th width=25% NOWRAP><a href="<?php echo $_SERVER['PHP_SELF']."?action=list_records"; ?>">
ID</a></th>
<th width=25% NOWRAP><a href="<?php echo $_SERVER['PHP_SELF']."?action=list_records"; ?>">
District</a></th>
<th width=25% NOWRAP><a href="<?php echo $_SERVER['PHP_SELF']."?action=list_records"; ?>">
Project_title</a></th>
<th width=25% NOWRAP>test</th>
</tr>
<?php
while ($query_data=mysql_fetch_array($result)){
$ID=$query_data["ID"];
$District=$query_data["District"];
$Project_title=$query_data["Project_title"];
echo "<tr>\n";
echo "<td>$ID</td>\n";
echo "<td>$District</td>\n";
echo "<td>$Project_title</td>\n";
echo "<td>.. keep for future </td>";
echo "</tr>\n";
}
?>
</table>
</DIV>
<?php
echo "<br>\n";
echo "<strong><center>";
echo "page_num: $page_num <br>";
echo "cur_page: $cur_page <br>";
if($page_num>1){
$prev_page=$cur_page-1;
echo "<a href=\"{$_SERVER['PHP_SELF']}?action=list_records&cur_page=0\">[top]</a>";
echo "<a href=\"{$_SERVER['PHP_SELF']}?action=list_records&cur_page=$prev_page\">[prev]</a>";
}
if($page_num<$total_num_page){
$next_page=$cur_page + 1;
$last_page=$total_num_page - 1;
echo "<a href=\"{$_SERVER['PHP_SELF']}?action=list_records&cur_page=$next_page\">[next]</a>";
echo "<a href=\"{$_SERVER['PHP_SELF']}?action=list_records&cur_page=$last_page_num\">[bottom]</a>";
}
echo "</strong></center>";
html_footer();
}
switch ($_GET['action']){
case "view_record";
break;
default:
list_records();
break;
}
?>
-----------------------
Thank you..
Winter