I'm very out of practice, and trying to figure out old broken code.
From a previous search page, results are pulled from the database, and the variables are passed. At first it works, but then, when I click on the pagination links to see the next page of results, it stops working. The next page appears with no info.
Here's the code, I think it has something to do with the passed variables toward the bottom of the code, but I can't figure out what to do.
<code>
<?php
require ('databaseconnection');
$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(),
descriptors.,
plantae.*
FROM
descriptors
LEFT JOIN
plantae ON (descriptors.plant_id = plantae.plant_name)
WHERE
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
descriptors.
,plantae.
FROM
descriptors
LEFT JOIN
plantae ON (descriptors.plant_id = plantae.plant_name)
WHERE
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">
<tr>
<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>
</tr>
';
while($row = mysql_fetch_array($data)){
echo '<tr>
<td align="left"> <a href="view_plant.php?id=' . $row['plant_name'] . '">View plant</a> </td>
<td align="left"> </td>
<td align="left">' . $row['scientific_name'] . '</td>
<td align="left">' . $row['common_name'] . '</td>
<td align="left">' . $row['leaf_shape'] . '</td>
</tr>';
}
echo '</table>';
}
if ($num_pages > 1) {
echo '<br /><p>';
$current_page = ($start/$display) + 1;
if ($current_page != 1) {
echo '<a href="leafsearch4c.php?s=' . ($start - $display) . '&np=;' . $num_pages . '&s1=' . $s1 . '&s2=' . $s2 . '&s3=' . $s3 . '&s4=' . $s4 . '">Previous</a> ';
}
for ($i = 1; $i <= $num_pages; $i++) {
if($i != $current_page) {
echo '<a href="leafsearch4c.php?s=' . (($display * ($i - 1))) . '$np=' . $num_pages . '&s1=' . $s1 . '&s2=' . $s2 . '&s3=' . $s3 . '&s4=' . $s4 .'">' . $i . '</a>';
} else {
echo $i . ' ';
}
}
if ($current_page != $num_pages) {
echo '<a href="leafsearch4c.php?s=' . ($start + $display) . '$np=' . $num_pages . '&s1=' . $s1 . '&s2=' . $s2 . '&s3=' . $s3 . '&s4=' . $s4 .'"> Next</a>';
}
}
//added curly
?></code>