Jump to content

displaying results from a mysql database


Recommended Posts



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


<style type="text/css">
body {background-image:url('images/greybgone.png');}


mysql_connect ("2up2downhomes.com.mysql", "2up2downhomes_c","mD8GsJKQ")  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 '<br/> Number of Bedrooms: '.$row['bedrooms'];
    echo '<br/> Number of Bathrooms: '.$row['bathrooms'];
echo '<br/> Garden: '.$row['garden'];
echo '<br/> Description: '.$row['description'];
echo '<br/> Price: '.$row['price'];
echo '<br/> Location: '.$row['location'];
echo '<br/> Image: '.$row['image'];
    echo '<br/><br/>';


Link to comment
Share on other sites

hello, maybe you should add



because when you hit 'search', the keyword you are searching is saved in $_POST['term']

so the $term in your sql instruction is equal to blank, which make it gives you all the result.

Hope it helps : )

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.