php mysql pagination problem
Posted: Fri Sep 01, 2006 3:01 am
In page one (form) there are two drop down menu, the result of which is sent to page two for selection from mysql and be paginated according to the number of listing.
Page 1
After javascript validation.
Page 2
receives the variables with no problem.
and displays the result for the first ten items.
There are 32 Nursing Homes in Wiltshire
Select a Page
1 2 3 4 Next Page
How ever if any of the above are clicked the variables are lost and the display changes to
There are 0 in
Select a Page
Previous Page
There are 0 in
Select a Page
Previous Page
page 2
If the variables are hard wired i.e.
the display works properly
also if the pagination is removed and using the $_GET or $REQUEST the display will show all items as one page.
At this stage it is only on local pc runing XP and phpdev5 not as service hence no security issue as yet.
Thank you in advance for any help
Page 1
Code: Select all
<?php
session_start();
?>Code: Select all
<form name="uk" ACTION="England/pages.php" method="GET" onSubmit="return ch4aForms()">receives the variables with no problem.
Code: Select all
<?php
$type = $_REQUEST ['type'];
$county = $_REQUEST['county'];
include ("encntype.php");
include ("type.php");
$htmls = ($encounty.".html");
if (file_exists($htmls)) {
include $htmls;
} else {
include ("nofile.html");
}
include ("enhead.html");
// Database Connection
include ("ez_sql.php");
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
// Define the number of results per page
$max_results = 10;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
// Perform MySQL query on only the current page number's results
$sql = mysql_query("SELECT * FROM ch4aengland WHERE HCN = '$encounty' && GRP = '$type' LIMIT $from , $max_results ");
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ch4aengland WHERE HCN = '$encounty' && GRP = '$type'"),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
// Build Page Number Hyperlinks
echo "<H2>There are ".$total_results ." " . $ntype ." in " . $encounty . "</H2>";
echo "<center>Select a Page<br /><br>";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\">Previous Page </a>";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\"> Next Page</a>";
}
echo "</center>";There are 32 Nursing Homes in Wiltshire
Select a Page
1 2 3 4 Next Page
How ever if any of the above are clicked the variables are lost and the display changes to
There are 0 in
Select a Page
Previous Page
There are 0 in
Select a Page
Previous Page
page 2
If the variables are hard wired i.e.
Code: Select all
$type = ['nu']; //type
$county = ['045'];//countyalso if the pagination is removed and using the $_GET or $REQUEST the display will show all items as one page.
At this stage it is only on local pc runing XP and phpdev5 not as service hence no security issue as yet.
Thank you in advance for any help