I'm building a search engine from scratch. My sql query is not giving me the output I would like. If I partially enter a word it will not match the query. If I enter the word exactly it will not match it all the time. Here is my query: $query = "SELECT DISTINCT * FROM `table` WHERE `name_id` LIKE '%$search%' ORDER by name_id ASC";
I think you need to append the content of $search variable $query = "SELECT DISTINCT * FROM `table` WHERE `name_id` LIKE '%" + $search+ "%' ORDER by name_id ASC";
That doesn't work. I get an error. Are you trying to concantate the string with the +'s? I'm using PHP.
That is not the problem. When you use double quotation mark in php, it's perfectly fine to use variables directly inside of them. And when you are concatenating strings in php you use a punctuation mark instead of a plus sign. The query looks perfectly fine to me. Are you sure the variable $search is exactly what you think it is?
Hi, I am a fresher php coder having very few knowledge. My question is: I want to achieve search result following way: say I have 13 listing under a certain keyword. when someone will search the keyword, then the search result will show 1-10, then when the same person searches the same keyword second time, the the search result will show 2-11, thus, then if i search the keyword again, the search result will show 3-12. can it be achieved ? if yes, then how ?
Few things: Your query in theory works fine - are you sure it SHOULD be returning rows? I'd suggest concatenating to avoid confusion on what is a variable and what isn't - however you use periods (.) instead of pluses (+) to do this in PHP Using a "SELECT *" and a "WHERE col LIKE '%'" is going to end up being very slowly if your site ever becomes popular or the database becomes large - I commend you for trying to build something new but perhaps you should rethink your query and platform
Yeah.. I found out about Sphinx Search. I'm going to try to implement that on my site instead of building a new engine. Trying to start a search engine from scratch was a lot more difficult than I planned.
agree, you need some more tables. a wordtable where you store each word you found on websites (without the stopwords like "the, then, there, we, me, i, in, of" etc.) and then a second where you store the website_id together with the word_id. your wordtable stays pretty small this way (there are only ~3-5000 common words in english) and the search is much faster than 'LIKE'. however, "building a search engine" is nothing you can do as a newbie over the weekend. understanding the human language is very difficult - thats why computer translators and search engines still suck so much.
Hi, I want to make a search system, where the first search result row will be moved to the end of the mysql table, so that when next time some of my website visitor will search for the same term, the previous first position result will appear at the end of the search result. for example: Tom searches my search engine for the keyword "wine company" , he get result with "ABC wine company" at 1st position and "XYZ wine company" ant 2nd position on the result page. Then if Tom or anyone else searches my search engine again with the same keyword, the result page will show "XYZ wine company" at first position and "ABC wine company at last position. Thus I want a rotation of the search result. So that no one can enjoy a static 1st position on my search engine. Please help