PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
SELECT * FROM property WHERE town LIKE '$town' AND beds = '$beds' AND
features LIKE '%$searchadv%' AND type = '$type' AND (price BETWEEN '$pricemin' AND '$pricemax')
When I use this in the SQL backend of the database itself, I enter this:
SELECT * FROM property WHERE town LIKE 'Hondon de los Frailes' AND beds = '4' AND features LIKE 'garage' AND type = 'Villa' AND (price BETWEEN '130000' AND '200000')
There is an entry in the DB for:
Hondon de los Frailes
4
'garage' is among a ton of info in the features field
Villa
195000
But it doesn't find it. It produces nothing. have I coded it wrong??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
<?php
if(isset($_POST['town']))
{
$town = $_POST['town'];
$_SESSION['town']=$town;
} else {
$town=$_SESSION['town'];
}
if(isset($_POST['searchadv']))
{
$searchadv = $_POST['searchadv'];
$_SESSION['searchadv']=$searchadv;
} else {
$searchadv=$_SESSION['searchadv'];
}
if(isset($_POST['pricemin']))
{
$pricemin = $_POST['pricemin'];
$_SESSION['pricemin']=$pricemin;
} else {
$pricemin=$_SESSION['pricemin'];
}
if(isset($_POST['pricemax']))
{
$pricemax = $_POST['pricemax'];
$_SESSION['pricemax']=$pricemax;
} else {
$pricemax=$_SESSION['pricemax'];
}
if(isset($_POST['beds']))
{
$beds = $_POST['beds'];
$_SESSION['beds']=$beds;
} else {
$beds=$_SESSION['beds'];
}
if(isset($_POST['type']))
{
$type = $_POST['type'];
$_SESSION['type']=$type;
} else {
$type=$_SESSION['type'];
}
include "dbconn.php";
echo "$town<br/>$searchadv<br/>$pricemin - $pricemax<br/>$beds<br/>$type";
$rowsPerPage = 16;
// by default we show first page
$pageNum = 1;
// if $_GET['pagenum'] defined, use it as page number
if(isset($_GET['pagenum']))
{
$pageNum = $_GET['pagenum'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
$result = mysql_query ("SELECT * FROM property WHERE town LIKE '$town' AND beds = '$beds' AND features LIKE '%$searchadv%' AND type = '$type' AND (price BETWEEN '$pricemin' AND '$pricemax') LIMIT $offset, $rowsPerPage") or die (mysql_error());
if (mysql_num_rows($result)==0) { echo "<div class='sectionhead'>Sorry, there are no results for your search. Go back and try again.<br/><br/>
<form method='post' action='index.php?page=searchadv&menu=home&head=Advanced Search'><input type='submit' value='Start new Search'>";
$pricemax = NULL;
$pricemin = NULL;
$town = NULL;
$type = NULL;
$searchadv = NULL;
echo "</form></div>"; }
elseif (mysql_num_rows($result)!=0) {
echo " <form method='post' action='index.php?page=searchadv&menu=home'><input type='submit' value='Start new Search'>";
$pricemax = NULL;
$pricemin = NULL;
$town = NULL;
$type = NULL;
$searchadv = NULL;
echo "</form>";
while ($row = mysql_fetch_object($result))
while ($row = mysql_fetch_object($result)) {
echo "
<div class='cat_prodlistbox'>
<div class='cat_producttitle'>";
echo "$row->reference €$row->price</div>";
if ($row->photoprimary == NULL) { echo "<a href='index.php?page=product&menu=categ&category=$row->town&product=$row->id&head=welcome to $row->town' title='Look at the $row->title'><img src='images/imageblank.png' border='0' /></a>";}
elseif ($row->photoprimary != NULL) { echo"
<a href='index.php?page=product&menu=categ&category=$row->town&product=$row->id&head=welcome to $row->town' title='Look at the $row->title'><img src='images/photos/$row->photoprimary' border='0' /></a>";}
echo "</div>";
}}
mysql_free_result($result);
echo "<div style='clear:both' /><hr noshade size='1' color='#cccccc' />";
$query = "SELECT COUNT(id) AS numrows FROM property WHERE town = '$town' AND beds = '$beds' AND type = '$type' AND features LIKE '%$searchadv%' AND (price BETWEEN '$pricemin' AND '$pricemax')";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nav .= " $page "; // no need to create a link to current page
}
else
{
$nav .= " <a href=\"index.php?page=searchadvresults&menu=home&pagenum=$page\" class='bodylink'>$page</a>";
}
}
// creating previous and next link
// plus the link to go straight to
// the first and last page
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"index.php?page=searchadvresults&menu=home&pagenum=$page\" class='bodylink'>[Prev]</a> ";
$first = " <a href=\"index.php?page=searchadvresults&menu=home&pagenum=1\" class='bodylink'>[First Page]</a>";
}
else
{
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"index.php?page=searchadvresults&menu=home&pagenum=$page\" class='bodylink'>[Next]</a>";
$last = " <a href=\"index.php?page=searchadvresults&menu=home&pagenum=$maxPage\" class='bodylink'>[Last Page]</a>";
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
}
// print the navigation link
echo "<div class='navpages'>" . $first . $prev . $nav . $next . $last . "</div>";
mysql_close($sqlconn);
?>
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.