balamberas Posted December 15, 2009 Share Posted December 15, 2009 Hi, I have a search engine script. It works fine when i search one word but if i would put i.e notting hill £900 it shows all the result from the data base. How can i make the script more flexible??? <?php include ('connect.php'); error_reporting(E_ALL); ini_set('display_errors', '1'); $submit = $_GET['submit']; $search = $_GET['search']; $x=0; $construct=''; $foundnum=0; if (!$submit) echo "you didnt submit a keyword."; else { if (strlen($search)<=2) echo "search term to short."; else { echo " You searched for <b>$search</b><hr size='1'>"; //connect to our database $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { // construct query $x++; if ($x==1) $construct .= " location LIKE '%$search_each%'"; else $construct .= " OR rent LIKE '%$search_each%'"; } // echo out construct $construct = "SELECT * FROM flats WHERE $construct"; $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if ($foundnum==0) echo "No results found."; else { echo "$foundnum result found!<p>"; while ($runrows = mysql_fetch_assoc($run)) { // get data $select = $runrows['type']; $title = $runrows['title']; $location = $runrows['location']; $rent = $runrows['rent']; $description = $runrows['description']; $contactEmail = $runrows['contactEmail']; $number = $runrows['number']; echo " $title <br> $select <br> $rent <br> $location <br> $description <br> $contactEmail <br> $number <hr>"; } } } } ?> Quote Link to comment Share on other sites More sharing options...
lAZLf Posted December 15, 2009 Share Posted December 15, 2009 $construct = "SELECT * FROM flats WHERE [table-column you want goes here] =$construct"; Try that and see how it works. Should be the only problem you have there. Quote Link to comment Share on other sites More sharing options...
balamberas Posted December 15, 2009 Author Share Posted December 15, 2009 hi, what if i want it to search through two columns. also when i search for i.e notting hill £900 it still shows all result even tho ive changed the mysql $construct = "SELECT * FROM flats WHERE location =$construct"; I want the script to be as flexible as possible Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.