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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.