Codeigniter表类垂直显示

问题描述 投票:1回答:1

使用codeigniter 3,我从MySQL数据库中检索一行,这是一个名为$tableData的数组,格式如下:

Array
(
    [0] => Array
        (
            [id] => 102
            [firstname] => Ross
            [lastname] => Bing
            [title] => Doctor
            [timestamp] => 2019-01-18 10:17:05
            [member_no] => 234
        )

)

使用CI table library如何在这样的垂直表中显示它;

+---------------+---------------------+
| id            | 102                 |
+---------------+---------------------+
| First Name    | Ross                |
+---------------+---------------------+
| Last Name     | Bing                |
+---------------+---------------------+
| Title         | Doctor              |
+---------------+---------------------+
| Timestamp     | 2019-01-18 10:17:05 |
+---------------+---------------------+
| Member Number | 234                 |
+---------------+---------------------+

我的PHP

foreach($tableData as $row) { 
    $this->table->add_row($row);
}

$data = array(
    'table' =>  $this->table->generate()
);

在我看来,我echo $table和数据显示成功 - 但它是水平的:/

php html mysql codeigniter codeigniter-3
1个回答
1
投票

也许这样的事情可以奏效。

$heading = array(
  'id' => 'custom name',
  'firstname' => 'custom name',
  'lastname' => 'custom name',
  'title' => 'custom name',
  'timestamp' => 'custom name',
  'member_no' => 'custom name'
);

$fields = array_keys($tableData[0]);
$rows = array();
foreach($fields as $key => $field) {
   $rows[$key][0] = $heading[$field];
   foreach($tableData as $key2 => $item) { 
        $rows[$key][$key2 +1] = $item[$field];
   }
}

foreach($rows as $row) {
    $this->table->add_row($row);
}

$data = array(
    'table' =>  $this->table->generate()
);

© www.soinside.com 2019 - 2024. All rights reserved.