..I have been strugling to get this part of my site working correctly even though I can't see anything wrong with my code. I am trying to search a database and display paged results. But everytime I perform a valid test expecting a few results to appear I am left with the No Matches message, so it's not a coding error as such. The code shown below is what I have for my search.php, please could someone put me out of my misery.
[code=php]
<html>
<head>
<style type="text/css">
.page_numbers {
width: 600px;
padding: 5px 0px;
float:left;
clear:left;
margin:0 auto;
}
.page_numbers ul {
margin: 0 auto;
list-style-type: none;
padding: 0px;
text-align: center;
}
.page_numbers li {
display: inline;
float: left;
margin:1px;
background: #a7a7a7;
width:25px;
}
.page_numbers li.current{
width:50px;
}
.page_numbers li a {
background: #fff;
border: 1px solid #a7a7a7;
padding: 1px;
text-decoration: none;
color: #000;
font:bold 8px verdana,sans-serif;
display:block;
}
.page_numbers a.current, .page_numbers li a:hover {
background: #a7a7a7;
color: #fff;
}
</style>
</head>
<body>
<?php
include "connection.php ";
$min_price = $_POST['min_price'];
$max_price = $_POST['max_price'];
$property_type = $_POST['type'];
$location = $_POST['location'];
$min_bedrooms = $_POST['min_beds'];
$keywords = $_POST['keywords'];
//$min_bedrooms = 2;
$webpage = basename($_SERV ER['PHP_SELF']);
function pagination_five ($total_pages,$ page){
global $webpage, $min_price, $max_price, $property_type;
global $location, $min_bedrooms, $keywords;
$max_links = 10;
$h=1;
if($page>$max_l inks){
$h=(($h+$page)-$max_links);
}
if($page>=1){
$max_links = $max_links+($pa ge-1);
}
if($max_links>$ total_pages){
$max_links=$tot al_pages+1;
}
if($total_pages >1){
echo '<div class="page_num bers"><ul>';
if($page>"1"){
echo '<li class="current" ><a href="'.$webpag e.'?page=1">Fir st</a></li>
<li class="current" ><a href="'.$webpag e.'?page='.($pa ge-1).'">Prev</a></li>
';
}
if($total_pages !=1){
for ($i=$h;$i<$max_ links;$i++){
if($i==$page){
echo '<li><a class="current" >'.$i.'</a></li>';
}
else{
echo '<li><a href="'.$webpag e.'?page='.$i.' ">'.$i.'</a> </li>';
}
}
}
if(($page >="1")&&($page! =$total_pages)) {
echo '<li class="current" ><a href="'.$webpag e.'?page='.($pa ge+1).'">Next</a></li>
<li class="current" ><a href="'.$webpag e.'?page='.$tot al_pages.'">Las t</a></li>
';
}
echo '</ul></div>';
}
}
$result = mysql_query("Se lect count(*) from search WHERE bedrooms = $min_bedrooms")
or die (mysql_error()) ;
$numrows = mysql_fetch_row ($result);
if(isset($_GET['pagenum'])?$page = $_GET['pagenum']:$page = 1);
$entries_per_pa ge = 1;
$total_pages = ceil($numrows[0]/$entries_per_pa ge);
$offset = (($page * $entries_per_pa ge) - $entries_per_pa ge);
//after we have $total_pages and $page, we can include the
//pagination style wherever we want on the page.
//so far there is no output from the script, so we could have
//pagination before or after the pages results
//before the results
$result = mysql_query("SE LECT * FROM search WHERE (price BETWEEN '$min_price' AND '$max_price' AND bedrooms >= '$min_bedrooms' AND location = '$location' AND type = '$property_type ' AND keywords LIKE '%$keywords%') OR
(price BETWEEN '$min_price' AND '$max_price' AND bedrooms >= '$min_bedrooms' AND location = '$location' AND type = '$property_type ') ORDER BY id ASC LIMIT
$offset,$entrie s_per_page");
if(!$result) die(mysql_error ());
$err = mysql_num_rows( $result);
if($err == 0) die("No matches met your criteria.");
while($row=mysq l_fetch_array($ result)){
$formatted = number_format($ row['price'],2);
echo "<div id=\"right\"><i mg src=\"".$row['image']."\"><a href=\"detail.p hp\">".$row['title']."</a><h4>Offers over £".$formatted." </h4><p>".$row['type'].", ".$row['bedrooms']." bedrooms</p><br /></div>\n";
}
//or after the results
pagination_five ($total_pages,$ page);
?>
</body>
</html>
[/code]
[code=php]
<html>
<head>
<style type="text/css">
.page_numbers {
width: 600px;
padding: 5px 0px;
float:left;
clear:left;
margin:0 auto;
}
.page_numbers ul {
margin: 0 auto;
list-style-type: none;
padding: 0px;
text-align: center;
}
.page_numbers li {
display: inline;
float: left;
margin:1px;
background: #a7a7a7;
width:25px;
}
.page_numbers li.current{
width:50px;
}
.page_numbers li a {
background: #fff;
border: 1px solid #a7a7a7;
padding: 1px;
text-decoration: none;
color: #000;
font:bold 8px verdana,sans-serif;
display:block;
}
.page_numbers a.current, .page_numbers li a:hover {
background: #a7a7a7;
color: #fff;
}
</style>
</head>
<body>
<?php
include "connection.php ";
$min_price = $_POST['min_price'];
$max_price = $_POST['max_price'];
$property_type = $_POST['type'];
$location = $_POST['location'];
$min_bedrooms = $_POST['min_beds'];
$keywords = $_POST['keywords'];
//$min_bedrooms = 2;
$webpage = basename($_SERV ER['PHP_SELF']);
function pagination_five ($total_pages,$ page){
global $webpage, $min_price, $max_price, $property_type;
global $location, $min_bedrooms, $keywords;
$max_links = 10;
$h=1;
if($page>$max_l inks){
$h=(($h+$page)-$max_links);
}
if($page>=1){
$max_links = $max_links+($pa ge-1);
}
if($max_links>$ total_pages){
$max_links=$tot al_pages+1;
}
if($total_pages >1){
echo '<div class="page_num bers"><ul>';
if($page>"1"){
echo '<li class="current" ><a href="'.$webpag e.'?page=1">Fir st</a></li>
<li class="current" ><a href="'.$webpag e.'?page='.($pa ge-1).'">Prev</a></li>
';
}
if($total_pages !=1){
for ($i=$h;$i<$max_ links;$i++){
if($i==$page){
echo '<li><a class="current" >'.$i.'</a></li>';
}
else{
echo '<li><a href="'.$webpag e.'?page='.$i.' ">'.$i.'</a> </li>';
}
}
}
if(($page >="1")&&($page! =$total_pages)) {
echo '<li class="current" ><a href="'.$webpag e.'?page='.($pa ge+1).'">Next</a></li>
<li class="current" ><a href="'.$webpag e.'?page='.$tot al_pages.'">Las t</a></li>
';
}
echo '</ul></div>';
}
}
$result = mysql_query("Se lect count(*) from search WHERE bedrooms = $min_bedrooms")
or die (mysql_error()) ;
$numrows = mysql_fetch_row ($result);
if(isset($_GET['pagenum'])?$page = $_GET['pagenum']:$page = 1);
$entries_per_pa ge = 1;
$total_pages = ceil($numrows[0]/$entries_per_pa ge);
$offset = (($page * $entries_per_pa ge) - $entries_per_pa ge);
//after we have $total_pages and $page, we can include the
//pagination style wherever we want on the page.
//so far there is no output from the script, so we could have
//pagination before or after the pages results
//before the results
$result = mysql_query("SE LECT * FROM search WHERE (price BETWEEN '$min_price' AND '$max_price' AND bedrooms >= '$min_bedrooms' AND location = '$location' AND type = '$property_type ' AND keywords LIKE '%$keywords%') OR
(price BETWEEN '$min_price' AND '$max_price' AND bedrooms >= '$min_bedrooms' AND location = '$location' AND type = '$property_type ') ORDER BY id ASC LIMIT
$offset,$entrie s_per_page");
if(!$result) die(mysql_error ());
$err = mysql_num_rows( $result);
if($err == 0) die("No matches met your criteria.");
while($row=mysq l_fetch_array($ result)){
$formatted = number_format($ row['price'],2);
echo "<div id=\"right\"><i mg src=\"".$row['image']."\"><a href=\"detail.p hp\">".$row['title']."</a><h4>Offers over £".$formatted." </h4><p>".$row['type'].", ".$row['bedrooms']." bedrooms</p><br /></div>\n";
}
//or after the results
pagination_five ($total_pages,$ page);
?>
</body>
</html>
[/code]
Comment