I have the paginated results page below, intended to show the results from a previous search page that pulls items from the database and also passes the _GET to this page. When I first submit my search, it works. But when I click on the paginated pages below, It reloads the page with out the next few entries from the database. It still shows the paginated numbers at the bottom. But I'm not sure why it's losing the database information?

require ('database connection');

$display = 2;
// it's intentionally only 2 for the moment to test pagination

if (isset($_GET['np'])) {
   $num_pages = $_GET['np'];
} else { 
$data = "SELECT COUNT(*),
                    LEFT JOIN
                        `plantae` ON (`descriptors`.`plant_id` = `plantae`.`plant_name`)
                        `leaf_shape` LIKE '%$s1%'
                        AND `leaf_venation` LIKE '%$s3%'
                        AND `leaf_margin` LIKE '%$s4%'";
$result = mysql_query ($data);

if (!$result) {
    die("Oops, my query failed.  The query is: <br>$data<br>The error is:<br>".mysql_error());

$row = mysql_fetch_array($result, MYSQL_NUM);
//row 40 above seems to be where a problem is 
$num_records = $row[0];

if ($num_records > $display) {
   $num_pages = ceil ($num_records/$display);
} else {
$num_pages = 1;
if (isset($_GET['s'])) {
   $start = $_GET['s'];
} else {
    $start = 0;

if(isset($_GET[submitted])) {
// Now collect all info into $item variable
$shape = $_GET['s1'];
$color = $_GET['s2'];
$vein = $_GET['s3'];
$margin = $_GET['s4'];

// This will take all info from database where row tutorial is $item and collects it into $data variable 

$data = mysql_query("SELECT
                    LEFT JOIN
                        `plantae` ON (`descriptors`.`plant_id` = `plantae`.`plant_name`)
                        `leaf_shape` LIKE '%$s1%'
                        AND `leaf_venation` LIKE '%$s3%'
                        AND 'leaf_margin' LIKE '%$s4%'
                    ORDER BY `plantae`.`scientific_name` ASC LIMIT $start, $display");

//chs added this in... 
echo '<table align="center" cellspacing="0" cellpading-"5">
<td align="left"><b></b></td>
<td align="left"><b></b></td>
<td align="left"><b>Leaf margin</b></td>
<td align="left"><b>Leaf venation</b></td>
//end something chs added in 

// This creates a loop which will repeat itself until there are no more rows to select from the database. We getting the field names and storing them in the $row variable. This makes it easier to echo each field.

while($row = mysql_fetch_array($data)){
echo '<tr>
<td align="left"> <a href="view_plant.php?id=' . $row['plant_name'] . '">View plant</a> &nbsp; &nbsp;</td>
<td align="left"> &nbsp;</td>
<td align="left">' . $row['scientific_name'] . '</td>
<td align="left">' . $row['common_name'] . '</td>
<td align="left">' . $row['leaf_shape'] . '</td>
echo '</table>';
if ($num_pages > 1) {
echo '<br /><p>';
$current_page = ($start/$display) + 1;
if ($current_page != 1) {
echo '<a href="leafsearch4c.php?&s1=' .$s1. '&s2=' .$s2. '&s3=' .$s3. '&s4=' .$s4. '&s=' . ($start - $display) . '&$np=' . $num_pages . '">Previous</a> ';

for ($i = 1; $i <= $num_pages; $i++) {
if($i != $current_page) {
echo '<a href="leafsearch4c.php?&s1=' .$s1. '&s2=' .$s2. '&s3=' .$s3. '&s4=' .$s4. '&s=' . (($display * ($i - 1))) . '&$np=' . $num_pages . '">' . $i . '</a>';
} else {
echo $i . ' ';

if ($current_page != $num_pages) {
 echo '<a href="leafsearch4c.php?&s1=' .$s1. '&s2=' .$s2. '&s3=' .$s3. '&s4=' .$s4. '&s=' . ($start + $display) . '&$np=' . $num_pages . '"> Next</a>';
//added curly

Edited by turpentyne: n/a

6 Years
Discussion Span
Last Post by turpentyne
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.