Iam creating a real estate website and I needed a search box on it. I don't know how to make it, I required users can search plot details by category example below

Note: all the field's are using Drop down box to show the value

1st box : Location (India) , 2nd box: Categeory (Villa,Residential Plot etc..)

3rd box: Min Budget (5Lac) 4th box :Max Budget (same value in the 3rd box)

We have already created the database and all the above value are store in one table. But we don't know how to create a search box for this. If the user select all the value and click on the submit button we need to take them to a search page (search.php) all the result will print there and pagination will show for more result to print from the same page.

If any body can help us please add the code with you comment Please Help me I know it is a simple one an experienced person can make it very easy. So please help it was for our college project we are stuck on this

Recommended Answers

All 2 Replies

are you getting an error?

post some code

Below is the code I use for my site's searching page. I had a similar question a while back and diafol answered it for me. This is a script he showed me to slim down my original process. You just need to do some tinkering in it to set it up to work with your fields and any specific things. It's pretty easy to do though.

$whereClause = array();
$bindArray = array();

$fields = array('location', 'category', 'min budget', 'max budget' 'ect'); 
foreach($fields as $field)
    if($san = filter_input(INPUT_POST, $field, FILTER_SANITIZE_STRING)){
        $whereClause[] = "`$field` = :$field";
        $bindArray[":$field"] =  $san;  
if(!empty($whereClause)) $sqlW = implode(' AND ', $whereClause);
$stmtString = $sql;
    $stmtString .= ' WHERE ' . $sqlW;
$dbh = new PDO('mysql:host=localhost;dbname= DB NAME;charset=utf8', 'DB USER', 'DB PASSWORD');
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$stmt = $dbh->prepare($stmtString);
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($data as $result)
   echo "There is a " . $result['category'] . ' in the contry of ' . $result['Location'] . ' that is listed for ' . $result['price'] . '<br />';
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.