Jump to content

Help with multi-array search query with delimited field.


fishwild

Recommended Posts

Ok. Need some help with this one.

 

I have a form that dynamically populates from the MySQL database using PHP.

 

Each distinct listing for three separate fields is shown in a series of check boxes.

 

The form, when submitted, populates three arrays based on checkbox selection. These arrays then run through the separate fields looking for a match for each instance selected.

 

 

THE PROBLEM:

One the the arrays ($form_array3) needs to run through a field with a possible list of delimited values. (i.e. Value1, Value 2, Value3, etc...)

 

If there is only one value in the field then the search works.

 

 

 

if($form_array1 || $form_array2 || $form_array3){

$sql .= " WHERE ";

if($form_array1){

foreach($form_array1 as $fa1){

$a[] = "form_array1='$fa1'";

}

$aj = join(" OR ",$a);

$fj[] = "(".$aj.")";

 

}

if($form_array2){

foreach($form_array2 as $fa2){

$b[] = "form_array2='$fa2'";

}

$bj = join(" OR ",$b);

$fj[] = "(".$bj.")";

 

}

if($form_array3){

foreach($form_array3 as $fa3){

$c[] = "form_array3='$fa3'";

}

$cj = join(" OR ",$c);

$fj[] = "(".$cj.")";

}

 

$sql .= join(" AND ",$fj);

 

}

 

Thanks for the help!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.