Now i need to search my text with the fields product_name and product_category. For ex. if i search "nokia mobile" then if category contains the word "mobile" and product_name contains the word "nokia" then it should come in the result set. This is just an example of text search. the searching text can be anything like "mobile nokia N 70" or "N 70 mobile" etc.
Can anybody help me over this, how can i do this efficiently?
Now i need to search my text with the fields product_name and product_category. For ex. if i search "nokia mobile" then if category contains the word "mobile" and product_name contains the word "nokia" then it should come in the result set. This is just an example of text search. the searching text can be anything like "mobile nokia N 70" or "N 70 mobile" etc.
Can anybody help me over this, how can i do this efficiently?
$query = mysql_query("SELECT * FROM table WHERE product_category='mobile' AND product_name='nokia' LIMIT 1;") OR die(mysql_error());
// if its either category OR name, THEN
$query = mysql_query("SELECT * FROM table WHERE product_category='mobile' OR product_name='nokia' LIMIT 1;") OR die(mysql_error());
Thanks for reply..
But the requirements are different buddy.....
I have only one text field in which user can type anything like "nokia mobile" , "nokia N 70" , "nokia", "mobile" or anything else for other products then mobile. so i can not use just OR , AND clauses only there must be some further logic for this..
djdon11 wrote:Thanks for reply..
But the requirements are different buddy.....
I have only one text field in which user can type anything like "nokia mobile" , "nokia N 70" , "nokia", "mobile" or anything else for other products then mobile. so i can not use just OR , AND clauses only there must be some further logic for this..
Thanks for your reply again,
Hi djdon11, As you can see I am new here.
I thought you want to pick up a row which had entries something like that. If you want to use it as search, then how about this.....
$search = '<--The thing user wants to search-->';
$query = mysql_query("SELECT * FROM table WHERE product_category LIKE '%$search%' OR product_name LIKE '%$search%';") OR die(mysql_error());
It'll pull up any row which matches/comes close to your search terms.
P.S. I am also working on a thing similar to this. So, I am also interested about this topic. IF anyone has a better option, I'll be glad to know as well.
Yes we can do that... but there is one more condition that if user enters suppose "nokia 70" then there should be listing of the record with the product name "nokia 70" only... ... that is why i avoided "%"
By the way Anand i have something for you if this can help you
Just replace the database connection and db name variables
$search = "nokia n70 mobile phone cheap price";
$query = explode(" ", $search);
# So, by this, query will be of 6 letters.
$query[0] = nokia
$query[1] = n70
#and so on.