dazz_club Posted April 21, 2008 Share Posted April 21, 2008 Hi guys, Ive come to the point of adding a search facility for my project. I've got one, but i think its a but loose. What i mean by this, if i type in dog, it will pull out everything that has d,o,g. would it be better to use match instead of like? if anyone has read useful search tutorials that they could post a link to, i would be most grateful. kind regards Darren Quote Link to comment Share on other sites More sharing options...
micah1701 Posted April 21, 2008 Share Posted April 21, 2008 it depends on what you're using for your search? what does your code look like now? usually, my searches are pulling stuff out of a database, so I just do something like: $search_for = "dog"; $query = "SELECT * FROM table WHERE some_column LIKE '%$search_for%' "; this will return anything that say's "Dog" or "Doggie" or "hotdog" etc... Quote Link to comment Share on other sites More sharing options...
dazz_club Posted April 21, 2008 Author Share Posted April 21, 2008 well here is the existing coding i am using; $query = "SELECT * FROM contacts WHERE first_name LIKE \"%$search%\" OR surname LIKE \"%$search%\" OR company_name LIKE \"%$search%\" OR position LIKE \"%$search%\" ORDER BY id DESC" . " LIMIT $offset, $rowsPerPage" ; i searching a table thats full of members, their name, where they live, you know the boring stuff. Well if i do type in dog in my search term in theory it shouldnt return anything, should it? As i have no members called dogs at all. kind regards Darren Quote Link to comment Share on other sites More sharing options...
micah1701 Posted April 21, 2008 Share Posted April 21, 2008 right, but the % wildcard in conjunction with the "LIKE" clause finds your $search string inside a larger string. so if a company's name is "dogwood industries" your search would find them Quote Link to comment 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.