从数据库填充数组

时间:2013-09-21 06:36:02

标签: php mysql arrays database

我需要从数据库填充数组,但必须采用以下格式:

$rows = array(         
   array("WD", "80GB","WD800AAJS SATA2 7200rpm 8mb"        ,"$36.90","Y"),
   array("WD","160GB","WD1600AAJS SATA300 8mb 7200rpm"     ,"$39.87","Y"),
   array("WD", "80GB","800jd SATA2 7200rpm 8mb"            ,"$41.90","Y"),
   array("WD","250GB","WD2500AAKS SATA300 16mb 7200rpm"    ,"$49.88","Y"),
   array("WD","320GB","WD3200AAKS SATA300 16mb 7200rpm"    ,"$49.90","Y"),
   array("WD","160GB","1600YS SATA raid 16mb 7200rpm"      ,"$59.90","Y"),
   array("WD","500GB","500gb WD5000AAKS SATA2 16mb 7200rpm","$64.90","Y"),
   array("WD","250GB","2500ys SATA raid 7200rpm 16mb"      ,"$69.90","Y"),
);

我这样做但是不起作用

$data = array();

foreach ($res as $value) {
    $data[] = array('afiliadios'=>
        array(
            $value[noEmpadronamiento],
            $value[docIdentificacion],
            $value[municipio],
            $value[departamento],
            $value[fechaAfiliacion],
            $value[apellido],
            $value[nombre])
        );
}

我想用pdf制作一份报告,这是我领导的链接

http://www.zedwood.com/article/136/generate-pdfs-with-php

1 个答案:

答案 0 :(得分:2)

如果你想生成类似的数组,那么应该是这样的。

$data = array();

foreach ($res as $value) {
    $data[] =  array(
            $value['noEmpadronamiento'],
            $value['docIdentificacion'],
            $value['municipio'],
            $value['departamento'],
            $value['fechaAfiliacion'],
            $value['apellido'],
            $value['nombre'])
        );
}