【问题标题】:codeigniter database array parsingcodeigniter 数据库数组解析
【发布时间】:2016-11-08 18:24:47
【问题描述】:

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

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

这会以一种非常草率的方式打印出整个数组。如果我有列名,我可以解析出值,但由于它们不同,我正在努力解决解析它的方法。

数组示例(有 5 列,ID、Brand、Model、Tested 和 Comment)

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();
    }

【问题讨论】:

  • 你在APPPATH . 'config/config.php'文件中设置了多少个数据库?
  • there are multiple databases 这到底是什么意思?你的意思是实际的数据库还是表?你介意显示你正在运行的查询吗?这样你会得到更好的帮助。
  • 是的,我的错误是有多个表而不是多个数据库。另外,我将模型和控制器添加到上面的帖子中以供参考。

标签: php mysql arrays database codeigniter


【解决方案1】:

我只是在我的控制器中创建了更多函数作为包装函数,然后为每个表创建了一个新页面。完美运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    • 2013-06-14
    • 2016-10-27
    • 2016-12-07
    相关资源
    最近更新 更多