adam.jones2 Posted February 8, 2012 Share Posted February 8, 2012 I need to create a search.php Whats the best practice for this? Search options are Make, Model, Min Price - Max Price I have attached what i have done so fare which works but not how i want Features i want is that if nothing is selected then it search the whole db also if only price is select it will return the results I have searched Google and surprised there not much info on this example search engine im looking for is http://www.motors.co.uk/ quicksearch.php Link to comment Share on other sites More sharing options...
adam.jones2 Posted February 9, 2012 Author Share Posted February 9, 2012 bump* Link to comment Share on other sites More sharing options...
Ingolme Posted February 9, 2012 Share Posted February 9, 2012 You haven't sanitized the input. People can use your code to hack the database. You should be using mysql_real_escape_string() on the input data. You should also get out of the habit of putting quotation marks around variable names like here: @mysql_query("$query") You seem to have it all working. All you need to do is take the results of the query and loop through them. W3Schools' PHP tutorial shows how to do that pretty well. though I prefer mysql_fetch_assoc() rather than mysql_fetch_array(). Link to comment Share on other sites More sharing options...
adam.jones2 Posted February 9, 2012 Author Share Posted February 9, 2012 Thanks i have taken you advice and updated the phpstill no feature where it searches the whole database if all value = "" also no feature where if i select Min price only it will search everything above that price range updates php attached quicksearch.php Link to comment Share on other sites More sharing options...
Ingolme Posted February 9, 2012 Share Posted February 9, 2012 Well, you need to add a bit of PHP to modify the query in those cases. It's nothing more than a few if() conditions. It shouldn't be too hard. Link to comment Share on other sites More sharing options...
adam.jones2 Posted February 9, 2012 Author Share Posted February 9, 2012 This what i have but does not workThis Just searches everythingplease help <?php$Make = $_POST['make']; // would equal Car name or ""$Min_Price = $_POST['pf'];$Max_Price = $_POST['pt'];$query = "SELECT * FROM site_cars";$result=mysql_query ($query);$filter = array();if (!empty($Make)) {$filter[] = "car_Make = $Make";}if (!empty($Min_Price)) {$filter[] = "car_price = $Min_Price";}if (!empty($Max_Price)) {$filter[] = "car_price = $Max_Price";}if (!empty($filters)) {$query .= ' WHERE ' . implode(' AND ', $filters);}?> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.