PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am making a custom search engine within my site, part of this feature is to search for records within my database which contain ALL words entered into the search box.
at the moment the keywords are split up and stuck into an array: $q_array
I then aim to do a for loop to go through each keyword entered, so at the mo I have something like ;
for ($d=0; $d<$q_num; $d++)
{
sql = "Select * from activities where title = $q_array[$d] or intro =$q_array[$d] or text=$q_array[$d]......etc"
}
but obviously as I am looking for activities that contain all keywords entered I need to have an AND statement (if there are 2 or more) there and replicate the above query for each keyword.
I'm not to sure how to do this and would appreciated if anyone could help
This splits all words seperated by a space, puts AND in between them, and then removes the extra AND at the end. Can't take credit for this is was posted to me a while back
No as I want the query to check each field in a row for the keyword
for example if i have 2 keywords; word1 and word2
for a record to be returned both word1 and word2 MUST appear in atleast 1 field in the row.
So what i need is a query that does the following:
sql = "select a record where word1 appears in field1 OR appears in field2 OR appears in field3 AND Where Word2 appears in field1 OR appears in field2 OR appears in field3"
"Select * from activities where (title like '%word1%' OR intro like '%word1%' OR text like '%word1%') AND (title like '%word2%' OR intro like '%word2%' OR text like '%word2%') AND(title like '%word3%' OR intro like '%word3%' OR text like '%word3%')"
is that what ur thinking or am I completely way off the mark!??