Hi:
I'm in my infancy of working with php. I've have tried multiple php scripts that i found for pagination with my SQL query without success. All of them succeed in displaying the navigation and providing the count of the number of pages there should be; however, all the scripts I've tried display the records all on one page. I believe there is a conflict with the WHERE clause, but it's a necessity and I cannot eliminate it. Here is my latest attempt. I am hoping someone will assist with a solution. I apologize in advance for the length.
My php script for my query:
<?php
$image_dir = '/images/inventory/';
$pl = trim($_GET['pl']);
$ph = trim($_GET['ph']);
if(empty($ph))
$ph = 999999;
else
$ph = (int)$ph; //make integer
if(empty($pl))
$pl = 0;
else
$pl = (int)$pl; //make integer
//echo "pl: $pl <br/>";
//echo "ph: $ph <br/>";
$new_pre = $_GET['new_pre'];
//echo "new_pre: $new_pre <br/>";
$hull_material = $_GET['hull_material'];
//echo "hull_material: $hull_material <br/>";
$make = $_GET['make'];
$callforprice = $_GET['callforprice'];
//echo "make: $make <br/>";
//$where_condition = "WHERE condition = '$new'
//AND condition = '$pre-owned'";
switch ($new_pre) {
case "b":
$where_new_pre = "AND new_pre LIKE '%'";
break;
case "n":
$where_new_pre = "AND new_pre = 'new'";
break;
case "p":
$where_new_pre = "AND new_pre = 'pre-owned'";
break;
}
switch ($hull_material) {
case "a":
$where_hull_material = "AND hull_material = 'aluminum'";
break;
case "f":
$where_hull_material = "AND hull_material = 'fiberglass'";
break;
case "b":
$where_hull_material = "AND hull_material LIKE '%'";
break;
}
switch ($make) {
case "any":
$where_make = "AND make LIKE '%'";
break;
case "contender":
$where_make = "AND make = 'contender'";
break;
case "century":
$where_make = "AND make = 'century'";
break;
case "hydra-sports":
$where_make = "AND make = 'hydra-sports'";
break;
case "alweld":
$where_make = "AND make = 'alweld'";
break;
case "hewes":
$where_make = "AND make = 'hewes'";
break;
case "cobia":
$where_make = "AND make = 'cobia'";
break;
case "maverick":
$where_make = "AND make = 'maverick'";
break;
case "pathfinder":
$where_make = "AND make = 'pathfinder'";
break;
case "twin vee":
$where_make = "AND make = 'twin vee'";
break;
}
$where_price = "WHERE price > $pl
AND price < $ph";
$where = " $where_price $where_new_pre $where_hull_material $where_make ";
$simple = TRUE;
if ($pl <> 0) $simple = FALSE;
if ($make <> '') $simple = FALSE;
if ($new_pre <> '') $simple = FALSE;
if ($hull_material <> '') $simple = FALSE;
$sql_simple = "SELECT * FROM boats ORDER BY price DESC";
$sql_search = "SELECT * FROM boats
$where
ORDER BY price DESC";
if ($simple) $sql = $sql_simple;
else $sql = $sql_search;
//echo "query: $query <br/>";
?>
Here's my display:
<?php
// Connects to your Database
require_once('inc/dbstuff.php');
include('ps_pagination.php');
$rs = mysql_query($sql)
or die(mysql_error());
Echo "<table width=400 class=thrColLiqHdr>";
while($row = mysql_fetch_array($rs))
{
Echo "<tr>";
Echo "<th>".$row['year'] . ' ' . $row['make'] . ' ' . $row['model'] . "</th>";
Echo "<th></th>";
Echo "<th></th>";
Echo "<th></th>";
Echo "<th>". (empty($row['price'])? $row['callforprice'] : '$' . $row['price']) . "</th></tr>\n";
Echo "<td><img src=\"$image_dir{$row['pix']}\" width=\"132\" height=\"99\" /></td>";
Echo"<td><strong>Location:</strong> ".$row['location'] . "</td> ";
Echo"<td><strong>Condition:</strong> ".$row['new_pre'] . "</td> ";
Echo"<td><strong>Engine:</strong> ".$row['engine_make'] . "</td> ";
Echo"<td>".'<form id="search-form" action="" method="get">'
.'<input name="boat_details" type="submit" value="Details" />'
."</form></td></tr>\n";
}
Echo "</table>";
/*
* Create a PS_Pagination object
*
* $conn = MySQL connection object
* $sql = SQl Query to paginate
* 10 = Number of rows per page
* 5 = Number of links
* "param1=valu1¶m2=value2" = You can append your own parameters to paginations links
*/
$pager = new PS_Pagination($conn, $sql, 10, 5);
/*
* Enable debugging if you want o view query errors
*/
$pager->setDebug(true);
/*
* The paginate() function returns a mysql result set
* or false if no rows are returned by the query
*/
$rs = $pager->paginate();
if(!$rs) die(mysql_error());
//Display the full navigation in one go
echo $pager->renderFullNav();
echo "<br />\n";
/*
* Or you can display the individual links for more
* control over HTML rendering.
*
*/
//Display the link to first page: First
//echo $pager->renderFirst();
//Display the link to previous page: <<
//echo $pager->renderPrev();
/*
* Display page links: 1 2 3
* $prefix = Will be prepended to the page link (optional)
* $suffix = Will be appended to the page link (optional)
*
*/
//echo $pager->renderNav('<span>', '</span>');
//Display the link to next page: >>
//echo $pager->renderNext();
//Display the link to last page: Last
//echo $pager->renderLast();
?>