Skip to main content
deleted 117 characters in body
Source Link
Sujit Agarwal
  • 12.5k
  • 11
  • 50
  • 79

This will probably be a pretty easy one for you programmers. I use php 3 or 4 X a year, so I get stumped easy.

My users put search terms in an input field. The script I'm using stores that in a $find variable. It then searches mysql like so:

"select * from mytable WHERE title LIKE '%$find%' or description LIKE '%$find%'";

I want to be able to pull a result, even if 1 word is in the title and another in the description, which currently doesn't happen. So.. I'm guessing I need to break the $find variable into an array with a function. After that, how would I do the search in mysql? Since I never know how many words will be in the search (they might decide to search for 8 words at once), how do I reference the array in the mysql query?

Thx in advance!

This will probably be a pretty easy one for you programmers. I use php 3 or 4 X a year, so I get stumped easy.

My users put search terms in an input field. The script I'm using stores that in a $find variable. It then searches mysql like so:

"select * from mytable WHERE title LIKE '%$find%' or description LIKE '%$find%'";

I want to be able to pull a result, even if 1 word is in the title and another in the description, which currently doesn't happen. So.. I'm guessing I need to break the $find variable into an array with a function. After that, how would I do the search in mysql? Since I never know how many words will be in the search (they might decide to search for 8 words at once), how do I reference the array in the mysql query?

Thx in advance!

My users put search terms in an input field. The script I'm using stores that in a $find variable. It then searches mysql like so:

"select * from mytable WHERE title LIKE '%$find%' or description LIKE '%$find%'";

I want to be able to pull a result, even if 1 word is in the title and another in the description, which currently doesn't happen. So.. I'm guessing I need to break the $find variable into an array with a function. After that, how would I do the search in mysql? Since I never know how many words will be in the search (they might decide to search for 8 words at once), how do I reference the array in the mysql query?

Thx in advance!

Source Link
Jeff
  • 19
  • 1
  • 3

Trying to do a php/mysql search and need to break string into array and search

This will probably be a pretty easy one for you programmers. I use php 3 or 4 X a year, so I get stumped easy.

My users put search terms in an input field. The script I'm using stores that in a $find variable. It then searches mysql like so:

"select * from mytable WHERE title LIKE '%$find%' or description LIKE '%$find%'";

I want to be able to pull a result, even if 1 word is in the title and another in the description, which currently doesn't happen. So.. I'm guessing I need to break the $find variable into an array with a function. After that, how would I do the search in mysql? Since I never know how many words will be in the search (they might decide to search for 8 words at once), how do I reference the array in the mysql query?

Thx in advance!