Jump to content

Need help with creating logic for searching table


jordanwb

Recommended Posts

I'm making a jukebox and I want the user to be able to search the songs in the database by it's name. What I want to do is get all the songs whose name contains any of the words in the search term. I found out you can use Regex in a sense:

 

SELECT * FROM `box_songs` WHERE `song_name` REGEXP 'Convoy'

 

 

What I'd like to do is sort the result by the number of matches between the search terms and the songs in the database, most matches first. I was thinking of getting all the records which contains any of the words in the search terms then using substr_count and add up all the occurances then sorting. That would work but it may be slow and a bubble sort would be inefficient.

 

Thanks.

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.