我有五个表,它们是由 php 中的 ListTable 函数创建的。
我有函数 ListTable3,其中是一个查询和结果表行。
function ListTable3($db, $host, $user, $pass, $start_vceraj, $end_vceraj, $start_danes, $end_danes, $start_date_danes, $start_date_vceraj, $trenutni_cas)
{
query("some query");
$result = mysqli_query($mysqli, $query);
while ($row = mysqli_fetch_array($result))
{
$output .=<table>
results rows
$output .=</table>
};
}
然后我用 for 循环调用这个函数 ListTable3,因为我调用同一个函数五次,只是来自不同的数据库。我创建了一个数据库数组,现在在 for 循环中,我为所有数据库一个一个地调用相同的函数 ListTable3。
代码:
$db_array = array($db_one,$db_two,$db_three,$db_four,$db_five);
for($y=0; $y < $st_db_array; $y++)
{
if($db_array[$y]!= $db_one)
{
$host=$host;
}
else {
$host = $host_one;
}
print "<tr>";
print "<td>";
$output = ListTable3($db_array[$y], $host, $user, $pass, $start_vceraj, $end_vceraj, $start_danes, $end_danes, $start_date_danes, $start_date_vceraj, $trenutni_cas);
print $output;
print "</td>";
print "</tr>";
}
所以当我运行我的页面时,我得到了五个包含数据的表,但它们没有合并。
我想得到一个表格,其中表格标题,然后将 for 循环中的五个表格合并为一个表格。任何人都可以给我任何建议或解决方案,我应该怎么做?
这是我所拥有的以及我需要做的事情的图片:http://postimg.org/image/jmmo5viuf/
谢谢大家的帮助
最佳答案
将查询逻辑与显示逻辑分开:
$data = array();
foreach($things_to_query as $thing) {
$newdata = listtable3($thing);
array_merge($data, $newdata); // you'll have to mod this
}
foreach($data) {
... display stuff here...
}
请注意,如所写,您的 listtable3 函数将永远无法工作。 $mysqli
未定义,这会使您的所有查询失败。
关于php - 合并在 php 中使用 ListTable 创建的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29567387/