displaying results from a mysql database

Hi

I have got results being displayed after clicking the search button in a form on my home page but it brings up all the results which is ok but how do I get onlt the results a user searches for for example a location or property type etc as its for a property website

The coding is below for the results page

Also sorry how do I add a background image to the php page, I tried using css but wouldn’t work

[php]
body {background-image:url(‘images/greybgone.png’);}

<?php mysql_connect ("****.com.mysql", "****_c","****") or die (mysql_error()); mysql_select_db ("2up2downhomes_c"); echo $_POST['term']; $sql = mysql_query("select * from properties where typeProperty like '%$term%' or location like '%$term%'"); while ($row = mysql_fetch_array($sql)){ echo 'Type of Property: '.$row['typeProperty']; echo '
Number of Bedrooms: '.$row['bedrooms']; echo '
Number of Bathrooms: '.$row['bathrooms']; echo '
Garden: '.$row['garden']; echo '
Description: '.$row['description']; echo '
Price: '.$row['price']; echo '
Location: '.$row['location']; echo '
Image: '.$row['image']; echo '

'; } ?>[/php]

Well, the background first… PHP can not set the background of the page because PHP is run SERVER-SIDE only and does not exist in the browser. It MUST be done either in your body tag or in CSS. But, you can use PHP to echo/print the CSS for you. So this should work if the image is in that folder:

background: url(images/greybgone.png);

Now, for part two, the search… Normally, you allow people to type in several words in the search field.
Then, you “explode” them into an array. And, loop thru them to pull the samples. First, I noticed you did
your search on the variable “$term”, but you did not actually pull this from the search field. You need to
change the “echo $_POST[‘term’];” to $term = $_POST[‘term’]; This will pull the field from the user’s
input. Now to explode the line of words into an array , it is very simple…
$words = explode(" ", $term);
What this will do is take each word typed in (AS-IS) using a space as the separation character.
Next, you would do a loop thru the $words array and do a search on each word. Something like this:
foreach ($words as $word){
$query=etc.etc. like $word .etc. etc… Just process the same as before using $word not $term
}
So, this is quite simple actually. Just 3 or so extra small lines… I am sure that will help you. Good luck!

Sponsor our Newsletter | Privacy Policy | Terms of Service