Hi:
While I have successful tried pagination with my database via a simpler script. I have not been able to successfully add it to the following script. Can someone assist? Sorry it is so lengthy.
<?php
$image_dir = '/test/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'];
//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;
$query_simple = "SELECT * FROM boats ORDER BY price DESC $limitQ";
$query_search = "SELECT * FROM boats
$where
ORDER BY price DESC
$limitQ";
if ($simple) $query = $query_simple;
else $query = $query_search;
//echo "query: $query <br/>";
?>
<?php
// Connects to your Database
require_once('inc/dbstuff.php');
$data = mysql_query($query)
or die(mysql_error());
Echo "<table width=400 class=thrColLiqHdr>";
while($row = mysql_fetch_array($data))
{
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=\"140\" height=\"105\" /></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>";
?>
So, the following php actually works for pagination, but I need combined with all the other stuff above so that everything else still works.
<?php
//include database connection (check previous posts to get this one)
require_once('inc/dbstuff.php');
//get the number of total rows
$query = "SELECT * FROM boats";
$result = mysql_query($query);
// Number of records found
$num_record = mysql_num_rows($result);
// Number of results per page
$display = 4;
if(isset($_GET['page'])) {
$currentPage = $_GET['page'];
}else{
$currentPage = 1;
}
//last page - we use ceil because page range is 1 to Max, this way page "2.5" becomes page 3
$lastPage = ceil($num_record/$display);
//limit in the query thing
$limitQ = 'LIMIT ' .($currentPage - 1) * $display .',' .$display;
//normal query and print results
$query = "SELECT * FROM boats $limitQ";
$result = mysql_query($query);
//here you do your loop like
Echo "<table width=400 class=thrColLiqHdr>";
while($row=@mysql_fetch_array($result))
{
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'])? 'Call for Price' : '$' . $row['price']) . "</th></tr>\n";
Echo "<td><img src=\"$image_dir{$row['pix']}\" width=\"140\" height=\"105\" /></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>";
//pagination navigation (links)
echo 'lastP= '.$lastPage; // for debug
//previous
if ($currentPage == 1) {
print "Prev ";
} else {
print "<a href=paginationtest.php?page=1>First page</a> ";
$previousPage = $currentPage-1;
print "<a href=paginationtest.php?page=$previousPage>Previous</a>";
}
print " { Page $currentPage of $lastPage } ";
//for next pages links
if ($currentPage== $lastPage) {
print "Next last";
} else {
$nextPage = $currentPage+1;
print " <a href=paginationtest.php?page=$nextPage>NEXT</a> ";
print " <a href=paginationtest.php?page=$lastPage>LAST</a> ";
}
?>
Tried combining several times with no success.