gpt4 book ai didi

php - 使用PHP foreach获取mysql表数据

转载 作者:行者123 更新时间:2023-11-29 04:03:58 26 4
gpt4 key购买 nike

我有 1 个数据库表包含行:

预订表:

attandee01  
attandee02
attandee03
attandee04
attandee05
attandee06

PHP 代码:

$q = $db->query("SELECT * FROM bs_events
LEFT JOIN bs_reservations ON bs_reservations.id_event = bs_events.id");

while($r = $q->fetch_array(MYSQLI_ASSOC)):
echo '<td>' . $r['attandee1'] . '</td>';
echo '<td>' . $r['attandee2'] . '</td>'
echo '<td>' . $r['attandee3'] . '</td>'
endwhile;

或者是否有任何简单的方法使用 foreach 来回显 attandee1 - attandee10?

最佳答案

$q = $db->query("SELECT * FROM bs_events
LEFT JOIN bs_reservations ON bs_reservations.id_event = bs_events.id");

while($r = $q->fetch_array(MYSQLI_ASSOC)):
foreach($r as $value) {
echo '<td>' . $value . '</td>';
}
endwhile;

应该回显每个表行的每个列值。

编辑:如果您只想要与会者:

$q = $db->query("SELECT * FROM bs_events
LEFT JOIN bs_reservations ON bs_reservations.id_event = bs_events.id");

while($r = $q->fetch_array(MYSQLI_ASSOC)):
for($i = 1; $i < 11 $i++) {
echo '<td>' . $r['attendee'.$i] . '</td>';
}
endwhile;

关于php - 使用PHP foreach获取mysql表数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5003099/

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