Jump to content

Broken pagination script


turpentyne

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/234527-broken-pagination-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.