Jump to content

[SOLVED] Building a Simple Search Feature on a Website


limitphp

Recommended Posts

I am building a music site, and I want to have a search feature that allows people to search for bands or songs or both from the artist on my website.

 

Do I just use simple queries to do this, or is there a standard different way to handle searches?

ex) select * where band = $query

select * where band = $query or song = $query

 

I couldn't find any tutorials on phpfreaks on the subject.

 

Thanks

 

 

 

Link to comment
Share on other sites

Huh?

 

When they search for a word using LIKE %$searchword% will search the selected db rows for any word that is or contains that word.

 

What if they put in two words and they want to search for any (band or song)?

 

would it look like this:

 

Select * from band, songs where band LIKE '%query%' OR song LIKE '%query%'

 

and lets say they typed in [The Strokes] in the search box.

 

Would that return any band that has The Strokes

 

or would it return any band that has 'the' in it as well as any band that has 'strokes' in it?

 

 

 

Link to comment
Share on other sites

Would look like

 

SELECT bandname,songname FROM table WHERE bandname LIKE '%".$query."%' OR songname LIKE '%".$query."%'"

 

And i don't think if someone searched the strokes it will look for the on it's own, i think it searches for the whole string.

 

Why the extra set of quotes and the periods?

Link to comment
Share on other sites

SELECT bandname,songname FROM table WHERE bandname LIKE '%".$query."%' OR songname LIKE '%".$query."%'"

 

Periods??

If you mean the column names (bandname, songname) this is just the columns of the table you will search and retrieve although you can use * for all of the columns.

 

The quotes

 

'%".$var."%'

 

Are not needed, i just like doing them as it is easier to read (when variables stand out) in my opinion but you can do

 

'%$var%'

Link to comment
Share on other sites

SELECT bandname,songname FROM table WHERE bandname LIKE '%".$query."%' OR songname LIKE '%".$query."%'"

 

Periods??

If you mean the column names (bandname, songname) this is just the columns of the table you will search and retrieve although you can use * for all of the columns.

 

The quotes

 

'%".$var."%'

 

Are not needed, i just like doing them as it is easier to read (when variables stand out) in my opinion but you can do

 

'%$var%'

 

Oh, ok.  Thanks guys!

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.