I am implementing jqGrid
with multiple search. But I have a trouble to get an array into single value. This is my code:
//I get this from url giving by jqGrid
$json_data = '{"groupOp":"OR","rules":[{"field":"first_name","op":"eq","data":"ale"},{"field":"last_name","op":"ne","data":"ger"},{"field":"first_name","op":"cn","data":"ros"}]}';
$myArray = json_decode($json_data);
$theArray = $myArray->rules;
foreach($theArray as $tArr)
{
//echoing field
$thisWhere = $tArr->field. " ";
//get operation
if($tArr->op == 'eq') {
$thisWhere .= '= '; //equal
$thisWhere .= '"'.$tArr->data.'" '.$myArray->groupOp.' ';
}
else if ($tArr->op == 'ne') {
$thisWhere .= '<> '; //not equal
$thisWhere .= $tArr->data.' '.$myArray->groupOp.' ';
}
else if ($tArr->op == 'lt') {
$thisWhere .= '< '; //less
$thisWhere .= $tArr->data.' '.$myArray->groupOp.' ';
}
else if ($tArr->op == 'le') {
$thisWhere .= '<= '; //less equal
$thisWhere .= $tArr->data.' '.$myArray->groupOp.' ';
}
else if ($tArr->op == 'gt') {
$thisWhere .= '> '; //greater than
$thisWhere .= $tArr->data.' '.$myArray->groupOp.' ';
}
echo $thisWhere; //echo inside foreach
//return ===> first_name = "ale" OR last_name <> "ger" OR first_name < 20 OR
}
//echo $thisWhere; //return ===> first_name < 20 OR
if echoing inside foreach
, return;
first_name = "ale" OR last_name <> "ger" OR first_name < 20 OR
if echoing outside foreach
, return; first_name < 20 OR
All I want is echoing or get $thisWhere
variable outside foreach
loop. So, I can do next step.