Sunday, May 12, 2013

Insert a group of data rows into table by Zend

fetchAssoc(): returns data in an array of associative arrays, using the first column as the array index. Example, import a group of rows into another table:

$data=$this->DB->fetchAssoc("SELECT MSSV, HoTen FROM sinhvien WHERE KhoaHoc=3");
foreach($data as $key=>$value){
$d=array(
 
  'MaSo'=>$value['MSSV'],
 
  'Ten'=>$value['HoTen']);
 
$this->DB->insert('thisinh',$d);
}
Another example:
print_r($db->fetchAll('select col1, col2 from table'));
Array
(
    [0] => Array
        (
            [col1] => 1
            [col2] => 2
        )
)

0 comments:

Post a Comment