概述
ive got 1 database table contains row:
TABLE FROM reservations:
attandee01
attandee02
attandee03
attandee04
attandee05
attandee06
PHP CODE:
$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 '
' . $r['attandee1'] . '';echo '
' . $r['attandee2'] . ''echo '
' . $r['attandee3'] . ''endwhile;
or is there any simple way using foreach to echo 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 '
' . $value . '';}
endwhile;
Should echo each column value per table row.
EDIT: If you only want the attendees:
$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 '
' . $r['attendee'.$i] . '';}
endwhile;
最后
以上就是刻苦手套为你收集整理的php mysql foreach_使用PHP foreach获取mysql表数据的全部内容,希望文章能够帮你解决php mysql foreach_使用PHP foreach获取mysql表数据所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复