limitphp Posted January 12, 2009 Share Posted January 12, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/140555-solved-building-a-simple-search-feature-on-a-website/ Share on other sites More sharing options...
premiso Posted January 12, 2009 Share Posted January 12, 2009 where band LIKE '%$query%' Use the like operator. You probably want to split the incoming data at the space and then use that as keywords. Just an fyi. Quote Link to comment https://forums.phpfreaks.com/topic/140555-solved-building-a-simple-search-feature-on-a-website/#findComment-735512 Share on other sites More sharing options...
limitphp Posted January 12, 2009 Author Share Posted January 12, 2009 You probably want to split the incoming data at the space and then use that as keywords. Just an fyi. so, I'll return results with either word or both words? Quote Link to comment https://forums.phpfreaks.com/topic/140555-solved-building-a-simple-search-feature-on-a-website/#findComment-735540 Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/140555-solved-building-a-simple-search-feature-on-a-website/#findComment-735542 Share on other sites More sharing options...
limitphp Posted January 12, 2009 Author Share Posted January 12, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/140555-solved-building-a-simple-search-feature-on-a-website/#findComment-735551 Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/140555-solved-building-a-simple-search-feature-on-a-website/#findComment-735556 Share on other sites More sharing options...
limitphp Posted January 12, 2009 Author Share Posted January 12, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/140555-solved-building-a-simple-search-feature-on-a-website/#findComment-735561 Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 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%' Quote Link to comment https://forums.phpfreaks.com/topic/140555-solved-building-a-simple-search-feature-on-a-website/#findComment-735563 Share on other sites More sharing options...
limitphp Posted January 12, 2009 Author Share Posted January 12, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/140555-solved-building-a-simple-search-feature-on-a-website/#findComment-735564 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.