Jump to content

"search" database and display results on website


rlgriffo

Recommended Posts

Hi, I am a complete newbie to PHP & mysql.

 

I have created a database for my website...i want to be able to search the database for a keyword eg "hairdresser" and for it to return all the entries which include this keyword.  I don't want people to see a search box or anything, i just want the results to be sitting there for them when they open that page.

 

I have learnt what i know so far (not much) from online tutorials, however i cant seem to find any information on how to display the data i have in my table in this manner.

 

If anyone could help me, provide me with some code or direct me to a online tutorial or something i would really appreciate it.

 

 

 

I'll assume you know how to connect to a database etc and I'll just write the query & display code:

 

$result = mysql_query("SELECT * FROM yourtable WHERE yourcolumn LIKE '%hairdresser%'");
while($row = mysql_fetch_assoc($result){
    echo 'Hairdresser found in '.$row['yourcolumn'].' with the id of '.$row['id'].'<br>';
}

 

This code queries the database and displays the results as a new line. This script assumes you have a column called id.

Archived

This topic is now archived and is closed to further replies.

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