sshrop Posted February 5, 2007 Share Posted February 5, 2007 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 More sharing options...
craygo Posted February 5, 2007 Share Posted February 5, 2007 Will they be searching a database for the information??? Are you looking for a search for a keyword and then a catagory to search that keyword on??? Ray Link to comment https://forums.phpfreaks.com/topic/37186-search-box-for-a-website/#findComment-177645 Share on other sites More sharing options...
sshrop Posted February 5, 2007 Author Share Posted February 5, 2007 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. Link to comment https://forums.phpfreaks.com/topic/37186-search-box-for-a-website/#findComment-177677 Share on other sites More sharing options...
craygo Posted February 5, 2007 Share Posted February 5, 2007 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 Link to comment https://forums.phpfreaks.com/topic/37186-search-box-for-a-website/#findComment-177703 Share on other sites More sharing options...
sshrop Posted February 5, 2007 Author Share Posted February 5, 2007 Thank you soooo much! This gives me the place I needed to start. I am intrigued by php and look forward to using it more. I appreciate your help. Link to comment https://forums.phpfreaks.com/topic/37186-search-box-for-a-website/#findComment-177737 Share on other sites More sharing options...
boo_lolly Posted February 6, 2007 Share Posted February 6, 2007 craygo's a damn good helper. Link to comment https://forums.phpfreaks.com/topic/37186-search-box-for-a-website/#findComment-177845 Share on other sites More sharing options...
sr20rps13 Posted February 6, 2007 Share Posted February 6, 2007 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. Link to comment https://forums.phpfreaks.com/topic/37186-search-box-for-a-website/#findComment-177852 Share on other sites More sharing options...
craygo Posted February 8, 2007 Share Posted February 8, 2007 Thanks boo!!! Ray Link to comment https://forums.phpfreaks.com/topic/37186-search-box-for-a-website/#findComment-180092 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.