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.

 

 

 

Link to comment
Share on other sites

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.

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.

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