I’m trying to replace a static way of getting data for a custom SQL by a dynamic way.
$filter1 = array( array('id' => 101, 'field' => 'name', 'name' => 'John'),
array('id' => 102, 'field' => 'name', 'name' => 'Mary'));
$custom_fields_array['Name_of_filter_1'] = $filter1;
foreach($custom_fields_array as $block_name => $block_array) {
if($block_array <> NULL) {
foreach($block_array as $bf_array) {
if(!empty($get_custom_fields) and in_array($bf_array['id'],$get_custom_fields)) {
if ($bf_array['id'] == 101) {
$custom_fields[] = 'pf.'.$bf_array['field'].' = "John" ';
} else if ($bf_array['id'] == 102) {
$custom_fields[] = 'pf.'.$bf_array['field'].' = "Mary" ';
}
}
}
}
}
Now the first thing I replaced ($filter1) works:
$cs_dl_query = mysqli_query("SELECT name FROM customers");
if (mysqli_num_rows($cs_dl_query)) {
$item = 100;
while($res_cs_dl = mysqli_fetch_array($cs_dl_query)){
$item++;
$cs_dl_array[] = array('id' => $item, 'field' => 'drive_links', 'name' => $res_cs_dl['drive_links']);
}
}
$filter1 = $cs_dl_array;
The problem is to prepare the if statements in the foreach block with the data collected for $filter1
I’ve tried to add it to a string and add the string in between the other if statements, but that just gives errors.
Any advice how I could dynamically create this:
else if ($bf_array['id'] == 102) {
$custom_fields[] = 'pf.'.$bf_array['field'].' = "Mary" ';
}