Page 1 of 1

php mysql pagination problem

Posted: Fri Sep 01, 2006 3:01 am
by johnboy
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

Code: Select all

<?php
session_start();
?>
After javascript validation.

Code: Select all

<form name="uk" ACTION="England/pages.php" method="GET" onSubmit="return ch4aForms()">
Page 2
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>";
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.

Code: Select all

$type = ['nu']; //type
$county = ['045'];//county
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

Posted: Fri Sep 01, 2006 5:38 am
by volka
Only session variables (stored in $_SESSION) are saved when session_start() has been called.
Everything else (including $_REQUEST) is lost when this request is served.

Your links do not include type and count. Therfore there is no _REQUEST [type/county] and your script cannot pull the records from the database.

php mysql pagination problem

Posted: Fri Sep 01, 2006 11:31 am
by johnboy
Hi Volka
Thanks for the quick reply.
I took my time as I had to look up $_SESSION tutorials which I have tried in various format without luck.
1, Do I call $_session_start() on page one or two
2, Do I put $_session into the form (instead of GET or POST)
3, How do I call the variables passed in the receiving page.
4, or Could you point me towards a good tutorial on $_session
:roll:

Thanks again in advance.

Re: php mysql pagination problem

Posted: Fri Sep 01, 2006 5:30 pm
by feyd
johnboy wrote:1, Do I call $_session_start() on page one or two
All pages which you want session data on, must start the session to see it's data.
johnboy wrote:2, Do I put $_session into the form (instead of GET or POST)
not possible.
johnboy wrote:3, How do I call the variables passed in the receiving page.
$_GET or $_POST depending on the submission method.
johnboy wrote:4, or Could you point me towards a good tutorial on $_session
The best tutorial I can suggest is by playing with them yourself.