Switch Inside Foreach Loop
Posted: Wed Sep 14, 2005 7:50 am
Hi all,
I'm a little grief setting the statement inside the switch.
Basically if $statement = ausapapersummary.manufacturerName or ausapapersummary.cpl use the LIKE sql command
Else use standard sql command. ($statement = $field)
Can anyone shed some light?
I'm a little grief setting the statement inside the switch.
Basically if $statement = ausapapersummary.manufacturerName or ausapapersummary.cpl use the LIKE sql command
Else use standard sql command. ($statement = $field)
Can anyone shed some light?
Code: Select all
$fields = array(
'ausapapersummary.paperCategoryId' => 'paperCategoryId',
'ausapapersummary.manufacturerName' => 'manufacturerName',
'ausapapersummary.cpl' => 'cpl',
'ausapapersummary.stockId' => 'stockId',
'ausapapersummary.adhesiveId' => 'adhesiveId',
'ausapapersummary.linerId' => 'linerId',
'ausapapersummary.supplierId' => 'supplierId',
'ausapapersummary.suitabilityFoil' => 'suitabilityFoil',
'ausapapersummary.suitabilityYellowLight' => 'suitabilityYellowLight',
'ausapapersummary.suitabilityLabel' => 'suitabilityLabel',
'ausapapersummary.suitabilityOpacity' => 'suitabilityOpacity',
'ausapapersummary.suitabilityBronze' => 'suitabilityBronze',
'ausapapersummary.suitabilityScreen' => 'suitabilityScreen',
'ausapapersummary.suitabilityIceBucket' => 'suitabilityIceBucket',
);
foreach ($fields as $statement => $field) { if (!empty($_POST[$field]) && $_POST[$field] > 0) {
$action = isset($_GET['action']) ? $_GET['action'] : '';
switch($action) {
case "ausapapersummary.manufacturerName" : $query .= " AND ".$statement." LIKE '%".$_POST[$field]."%'"; break;
case "ausapapersummary.cpl": $query .= " AND ".$statement." = ".$_POST[$field].""; break;
default: $query .= " AND ".$statement." = ".$_POST[$field].""; break;
}
}
}