microbert Posted May 28, 2013 Share Posted May 28, 2013 Hi,I am trying to build a search page that searches MySQL database. I managed to do the search, but I have a small problem when giving the query.Ex: If for example I am searching for "how to make a search" and I type "make a search" - it works fine but if It type "how to search" it doesn't work. can someone help me out since I am loosing my mind on this.my sql command is: $SQL = mysql_query("SELECT * FROM stocks WHERE `name` LIKE '%$keywords%' order by code"); help is very appreciated Quote Link to comment https://forums.phpfreaks.com/topic/278472-search-in-mysql-from-php/ Share on other sites More sharing options...
Eiseth Posted May 28, 2013 Share Posted May 28, 2013 Because LIKE will search using the whole keyword and not word by word Quote Link to comment https://forums.phpfreaks.com/topic/278472-search-in-mysql-from-php/#findComment-1432733 Share on other sites More sharing options...
Barand Posted May 28, 2013 Share Posted May 28, 2013 Have a look at MySQL FULLTEXT searches Quote Link to comment https://forums.phpfreaks.com/topic/278472-search-in-mysql-from-php/#findComment-1432734 Share on other sites More sharing options...
microbert Posted May 28, 2013 Author Share Posted May 28, 2013 But is there a way to search word by word? Quote Link to comment https://forums.phpfreaks.com/topic/278472-search-in-mysql-from-php/#findComment-1432735 Share on other sites More sharing options...
microbert Posted May 28, 2013 Author Share Posted May 28, 2013 My Database id InnoDB and it is not supported with FULLTEXT Search. Is there another way to do this? Quote Link to comment https://forums.phpfreaks.com/topic/278472-search-in-mysql-from-php/#findComment-1432738 Share on other sites More sharing options...
Barand Posted May 28, 2013 Share Posted May 28, 2013 WHERE name LIKE '%$word1%' AND name LIKE '%$word2%' AND name LIKE '%$word3%' Quote Link to comment https://forums.phpfreaks.com/topic/278472-search-in-mysql-from-php/#findComment-1432745 Share on other sites More sharing options...
microbert Posted May 28, 2013 Author Share Posted May 28, 2013 To be fair I have tried to explode the keywords into an array and then run a look to make the sql command but it didn't work. I was hoping there is another way to make this work. Quote Link to comment https://forums.phpfreaks.com/topic/278472-search-in-mysql-from-php/#findComment-1432747 Share on other sites More sharing options...
Barand Posted May 28, 2013 Share Posted May 28, 2013 Sphinx supports InnoDB Quote Link to comment https://forums.phpfreaks.com/topic/278472-search-in-mysql-from-php/#findComment-1432750 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.