在PHP中,如何在表格中显示数组内容
如果我在 MySQL 客户端中进行选择,我将得到如下所示的输出:
mysql> select * FROM `group` LIMIT 2;
+----------+---------------------+-----------------+-------------+
| group_id | group_supergroup_id | group_deletable | group_label |
+----------+---------------------+-----------------+-------------+
| 1 | 4 | 0 | defaut |
| 8 | 1 | 1 | dbdfg |
+----------+---------------------+-----------------+-------------+
How can I conversion a PDO fetch
(or fetchAll
) array in a table like that ?
这是一个代码使用示例:
$prep = $pdo->query('SELECT * FROM `group` LIMIT 2;');
$arr = $prep->fetchAll(PDO::FETCH_ASSOC);
echo renderMySQLTable($arr);
If I do a select in the MySQL client, I will have output that looks like this:
mysql> select * FROM `group` LIMIT 2;
+----------+---------------------+-----------------+-------------+
| group_id | group_supergroup_id | group_deletable | group_label |
+----------+---------------------+-----------------+-------------+
| 1 | 4 | 0 | defaut |
| 8 | 1 | 1 | dbdfg |
+----------+---------------------+-----------------+-------------+
How can I convert a PDO fetch
(or fetchAll
) array in a table like that?
Here's a code usage example:
$prep = $pdo->query('SELECT * FROM `group` LIMIT 2;');
$arr = $prep->fetchAll(PDO::FETCH_ASSOC);
echo renderMySQLTable($arr);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
类似于 mysql 客户端 输出的内容:
Something close to what mysql client outputs:
不过,非 pdo 方法:)
对于数组来说,这并不难。几个循环,你就得到了你需要的。
从运行
print_r($arr)
开始查看它的结构non-pdo aproach though :)
for the array it's not that hard. a few loops and you've got you need.
start from running
print_r($arr)
to see it's structure使用Table,并在css中提供一些样式。
use Table, and give a bit of style in css.