gpt4 book ai didi

php - codeigniter数据库数组解析

转载 作者:行者123 更新时间:2023-11-29 20:02:00 25 4
gpt4 key购买 nike

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

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

Controller

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

最佳答案

我只是在 Controller 中创建了更多函数作为包装函数,然后为每个表创建了一个新页面。工作完美。

关于php - codeigniter数据库数组解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40493953/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com