繁体   English   中英

codeigniter数据库数组解析

[英]codeigniter database array parsing

我对代码点火器非常陌生,因此我可能做错了,但是无论如何。 我正在尝试显示一个数据库,但问题是有多个表,每个表的列数和列名各不相同。

foreach ($database as $value) {
    print_r($value);
}

这会非常草率地打印出整个阵列。 如果我有列名,我可以解析出值,但是由于它们有所不同,因此我正在努力寻找一种解析它的方法。

数组示例(具有5列,ID,品牌,型号,已测试和注释)

Array ( [ID] => 3 [Brand] => IBM [Model] => Thinkcentre 8215-E9U [Tested] => 1 [Comment] => ) 
Array ( [ID] => 1 [Brand] => MGP [Model] => Thinkcentre 8183-T6U [Tested] => 1 [Comment] => ) 
Array ( [ID] => 2 [Brand] => IBM [Model] => Thinkcentre 8215-22U [Tested] => 1 [Comment] => ) 
Array ( [ID] => 4 [Brand] => IBM [Model] => Thinkcentre 8215-W97 [Tested] => 1 [Comment] => )

模型

public function select_videocards() {
        $this->load->database();
        $query = $this->db->get('tbl_videocards');
        return $query->result_array();
    }

控制者

 $table = NULL;

    if($this->input->server('REQUEST_METHOD') == 'POST') { // POST has been received
            $table = $this->input->post('table');
    }

    $data['title'] = ucfirst($page); // Capitalize the first letter
    $data['table'] = $table;

    if($table!="select" AND $table!=NULL) {
        echo $table;
        $data['database'] = $this->Inventory_model->$table();
    }

我只是在控制器中做了一些包装函数,然后为每个表创建了一个新页面。 工作完美。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM