Happy Holidays to all!
I have a mysql query that in its basic form is as follows:
SELECT * FROM personals WHERE column LIKE '%$pattern%';
I have several columns to compare $pattern to. So instead of writing a loooooong query, I decided to put the mysql table columns into an array.
$pattern is a search term that the user submits in a form, hence $pattern can also be more than a single word, separated by spaces. So I decided to break $pattern up into an array also.
The query then becomes something like this:
SELECT * FROM personals WHERE column[$i] LIKE '%$pattern[$loop]%';
Here is the php for it:
$paramArray = Array("state","city","ethnicity","title","description","body","job");
$lenPrmArray = sizeof($paramArray);
include ("connect.php");
$db = "personals";
for($loop=0; $loop < $lenPrmArray; $loop++)
{
$sql = "select * from personals.personals where ";
$pattern_list = explode(" ",addslashes($pattern));
$lenPtnLst = sizeof($pattern_list);
for ($x = 0; $x < $lenPtnLst; $x++)
{
$sql .= " $paramArray[$loop] like '%$pattern_list[$x]%' OR ";
}
}
...
My hope is that for each iteration of $loop, the inner FOR loop will execute $lenPtnLst times.
Is there any sense in this idea, or should I just drop the table column array, and write out the query in full?
I could just run it and see if it works, but the script is big. Knowing that this part makes sense would make debugging a lot easier for me.
I'll appreciate your help on this one. Thx.
Richie.