php - Looping fails only iterate the last sequence of data in arrays -


i have lines of data on table shown below :

+-------------------+-------+ | criteria          | value | +-------------------+-------+ | pengalaman kerja  |     4 | | pendidikan        |     3 | | usia              |     5 | | status perkawinan |     2 | | alamat            |     6 | | pengalaman kerja  |     3 | | pendidikan        |     1 | | usia              |     4 | | status perkawinan |     2 | | alamat            |     1 | +-------------------+-------+ 10 rows in set (0.00 sec) 

when iterate through data above in php using mysqli fetch_object, want create new arrays end :

array (     [pengalaman kerja] => array         (             [1] => 4             [2] => 3         )      [pendidikan] => array         (             [1] => 3             [2] => 1         )      [usia] => array         (             [1] => 5             [2] => 4         )      , on.. ) 

i've been hardly trying , boiling head these array things , ended in code shown below :

 $result      = $db->query($sql);   while($row=$result->fetch_object()){     if(!isset($isi[$row->criteria])){      $isi[$row->criteria] = array();    }     $isi[$row->criteria] =     array(1 => $data[$row->name][$row->criteria]);       $number = count($data);    ($i=2; $i<=$number; $i++) {        array_push($isi[$row->criteria], $row->value);    } } 

the wrapping arrays correct, errors in values of each wrapping array. code above took last sequence of data :

 array  (     [pengalaman kerja] => array        (             [1] => 4             [2] => 4        )      [pendidikan] => array        (             [1] => 3             [2] => 3        )      [usia] => array        (             [1] => 5             [2] => 5        )      , on.. ) 

could guys me elaborating wrong things in code , how fix expected result?

thank in advance.

edit :

this how loop through data

if(!isset($isi[$row->criteria])){      $isi[$row->criteria] = array(); } $isi[$row->criteria][] = $row->value; 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -