YVS1102 YVS1102 - 5 months ago 26
PHP Question

If condition Inside fetch_array

Good day, Please check my script first.

$fields = $query->list_fields();

foreach($query->result_array() as $data){
if($row % 2 == 0){
//blabla
}
$col = 1;
foreach ($fields as $field){
if($data[$field]['Stats'] == 0){ //In this part

}
}
$row++;
$no++;
}


So, i want to check specified field that named with
Stats
. My Problem is how i do
If Conditional statement there
. Because with my script above i always get false.

result when i print
$data


Array
(
[Kode Otlet] => K-BDCW2
[Area] => BANDUNG
[Nip] => 1500029
[Nama Lengkap] => AHMAD ILHAM YUSUP
[Posisi Sebelumnya] => VMO
[Posisi Baru] => VMO
[Tanggal Upgrade/Demosi] => 2016-06-03
[Stats] => 0
[1] => 7
[2] => 7
[3] => 7
[4] => 7
[5] => 7
)

Answer

You not need to use the $fields, Without $fields you can do it like:

if($data['Stats'] == 0){ //do }

Or, if your want to use $fields then you need to double check the condition like:

if($data[$field] == 0 && $field == 'Stats'){ //do }
Comments