Jump to content

Search Box for a Website


sshrop

Recommended Posts

Hello,

I have a need for a search box on my website.  I need for clients to be able to search for houses in a certain town or area.  I need it to pull up the houses for them to view.  I am just getting started with php and wondered what they would be called so I can research how to create it.

Thanks for any help...

 

Link to comment
https://forums.phpfreaks.com/topic/37186-search-box-for-a-website/
Share on other sites

I'm up for discussion.  Which do you think would be better?  I am in the development stage of the site right now.  It is a "For Sale By Owner" real estate site.  There will be houses listed on the site that are for sale.  They are in 5 different counties.  They also have ID #'s.  I am looking for a way for clients visiting the site to find either an ID number or a house in a certain county, city etc. 

I usually use dreamweaver to design sites and never really used php.  I know there are a lot of benefits of php and I would like to learn.  I guess I really need the easiest solution for now and then after I learn a little more I could upgrade it.  I would like for the results of the search to pull up on a page with the houses listed. 

OK lets say you have a database called "realestate" and in that database you have a table called "listings"

in the table you have a couple fields called

 

property_ID AND county

 

Granted they can be whatever you want to call them but for this example I will code using the above.

 

<?php
if(isset($_POST['submit'])){
// Database settings
$dbhost = 'localhost';
$dbname = 'realestate';
$dbuser = 'xxxxxxxx';
$dbpass = 'xxxxxxxx';
// Make connection to database
$mysql_conn = @mysql_connect($dbhost, $dbuser, $dbpass) or die("Could not connect to Mysql Server");
@mysql_select_db($dbname, $mysql_conn) or die("Could not connect to Database");

$keyword = mysql_real_escape_string($_POST['keyword']);
$field = mysql_real_escape_string($_POST['fieldname']);

$sql = "SELECT * FROM listings WHERE $field LIKE '%$keyword%'";
$res = mysql_query($sql) or die (mysql_error());
  while($r=mysql_fetch_assoc($res)){
  echo $r['property_ID'].", ".$r['county']."<br />";
  // any other fields list them below


  }
} else {
?>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method=POST>
<table width=500 align=center>
  <tr>
    <td width=250>Keyword:  <input type=text name=keyword /></td>
    <td width=250>Search By:  
      <select name=fieldname>
<?php
$fields = array(0 => "--Select by--", "property_ID" => "Property ID", "county" => "County");
foreach($fields as $key => $value){
  echo "<option value=\"".$key."\">$value</option>";
}
?>
      </select>
    </td>
  </tr>
</table>
</form>
<?php
}
?>

 

Ray

 

Personally, I would go attack it this way:

 

Create a database called real estate.

Create a table called details.

Create columns with details such as price, the url of the picture of the house, size, etc...

Create a form that searches the table and returns the result.

Create a form to add your submissions or you can do it through phpmyadmin.

 

It shouldn't take too long if you've got it all planned out.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.