ADODB5 (PHP):动态构建表列
我想知道如何在adodb5中动态生成表列。
这是我当前的代码:
<?php
$sql = "SELECT id FROM customers";
$query = $db->Execute($sql);
$rows = $query->GetRows();
$fields = $query->fields;
foreach($rows as $row) {
print_r($row). '<br />';
}
?>
我收到的输出是:
Array ( [id] => 280 ) Array ( [id] => 1024 ) Array ( [id] => 474 ) Array ( [id] => 476 ) Array ( [id] => 564 ) Array ( [id] => 569 ) Array ( [id] => 594 ) Array ( [id] => 385 ) Array ( [id] => 304 ) Array ( [id] => 700 ) Array ( [id] => 285 ) Array ( [id] => 205 ) Array ( [id] => 536 ) Array ( [id] => 140 )
我实际上只是希望它获取查询中的所有列并构建表头。所以基本上,我将有一个表,其中一列下包含所有“ID”。我实际上想要标记列,所以万一我有多个列,例如 ID、名称、日期、评论;它会动态地知道如何为每列制作标题。这是可以帮助我的人吗?
I'm wanting to know how to dynamically generate the table columns in adodb5.
Here's my current code:
<?php
$sql = "SELECT id FROM customers";
$query = $db->Execute($sql);
$rows = $query->GetRows();
$fields = $query->fields;
foreach($rows as $row) {
print_r($row). '<br />';
}
?>
The output I recieve is:
Array ( [id] => 280 ) Array ( [id] => 1024 ) Array ( [id] => 474 ) Array ( [id] => 476 ) Array ( [id] => 564 ) Array ( [id] => 569 ) Array ( [id] => 594 ) Array ( [id] => 385 ) Array ( [id] => 304 ) Array ( [id] => 700 ) Array ( [id] => 285 ) Array ( [id] => 205 ) Array ( [id] => 536 ) Array ( [id] => 140 )
I'm literally just wanting it to grab all the columns in the query and build the table headers. So basically, I will have a table that has all the "ID"'s under one columns. I actually want the columns labeled, so in case I have more than one columns, for example, ID, Name, Date, Comment; it would dynamically know how to make the headers for each columns. Is this someone that can help me with?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您首先需要修改获取数据行的查询:
或者如果您只想要某些列:
然后您可以迭代行并看到您有一个对象或关联数组(我忘记了哪个),它允许您布局您的桌子。对于标头,您已经拥有
$fields
,因此只需迭代即可形成标头:希望这会有所帮助。
You first need to modify your query that gets the data rows:
or if you only want certain columns:
you can then iterate through the rows and see you have an object or an associative array (I forget which) that allows you to lay out your table. For the headers you already have the
$fields
so just iterate to form the header:Hope this helps.