Jump to content

extra pagination links don't show query results


turpentyne

Recommended Posts

I've got a page with pagination set up, but I can't figure out where I went wrong with the links at the bottom.

 

When I do a search, it generates the proper number of links, but clicking on the links goes to a page with a whole row of 20 links at the bottom and no results on the page. (my search should show 3 pages with 2 records on each page)

 

I've looked through the tutorial here and one in a book on pagination. Not seeing what's wrong. I'd narrow this down if I knew where it was causing the problem. pagination links are at the very bottom of the code.

 



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>search.html</title></head>
<body>
<center>
<p>The results of your search:</p>
<br>
</center>
require ('databaseconnect.php');

$select = mysql_select_db($db, $con);
if(!$select){
die(mysql_error());
}

$display = 2;

if (isset($_GET['np'])) {
   $num_pages = $_GET['np'];
} else { 
$data = "SELECT COUNT(*)
                    FROM
                        descriptors
                    LEFT JOIN
                        plantae ON (descriptors.plant_id = plantae.plant_name)
                    WHERE
                        `leaf_shape` LIKE '%$select1%'
                        AND `leaf_venation` LIKE '%$select3%'
                        AND `leaf_margin` LIKE '%$select4%'";
                    
  
$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 41
$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($_POST[submitted])) {
// Now collect all info into $item variable
$shape = $_POST['select1'];
$color = $_POST['select2'];
$vein = $_POST['select3'];
$margin = $_POST['select4'];




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

$data = mysql_query("SELECT
                        `descriptors`.*
                        ,`plantae`.*
                    FROM
                        `descriptors`
                    LEFT JOIN
                        `plantae` ON (`descriptors`.`plant_id` = `plantae`.`plant_name`)
                    WHERE
                        `leaf_shape` LIKE '%$select1%'
                        AND `leaf_venation` LIKE '%$select3%'
                        AND `leaf_margin` LIKE '%$select4%'
                    ORDER BY `plantae`.`scientific_name` ASC LIMIT $start, $display");



//chs added this in... row 72
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>
';

// 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="link.php">View plant</a>    </td>
<td align="left"> <a href="link.php">unknown link</a>   </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;
// row 100
if ($current_page != 1) {
echo '<a href="leafsearch2a.php?s=' . ($start - $display) . '&np=;' . $num_pages . '">Previous</a> ';
}

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

if ($current_page != $num_pages) {
echo '<a href="leafsearch2a.php?s=' . ($start + $display) . '$np=' . " " . $num_pages . '">  Next</a>';
}
} 
?>

</body></html>

 

Link to comment
Share on other sites

I'm still completely lost on this. I've looked at tutorials. I've read books. I'm missing something and I don't know what.

The best guess I can come up with is that the _post variables that were searched for do not pass through correctely (or at all?) when I click on the pagination links on the bottom. I've had the same thing happen on a couple different scripts.

 

please please, can somebody help? I'm struggling to understand what I'm doing here.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.