如何将列表放入while循环?
PHP:
> $q = $db->query("SELECT * FROM
> bs_events LEFT JOIN bs_reservations ON
> bs_reservations.id_event = bs_events.id
> GROUP BY bs_reservations.id_event
> ORDER BY bs_events.eventDate ASC LIMIT 20");
HTML 表格:
> while($r = $q->fetch_array(MYSQLI_ASSOC)):
> echo '<tr>';
> echo '<td>' . $r['title'] . '</td>';
> echo '<td>' . date('d/M/Y', strtotime($r['eventDate'])) . ' / ' . $r['eventTime'] . '</td>';
> echo '<td>' . $r['location'] . '</td>';
> echo '<td>' . array($r['username']) .'</td>';
> echo '<td ></td>';
> echo '<td ></td>';
> echo '</tr>';
> endwhile;
上面的代码将输出
TITLE DATE/TIME LOCATION USERNAME
=================================================
1 dd/mm/yyy / hh:mm location username
1 dd/mm/yyy / hh:mm location username1
1 dd/mm/yyy / hh:mm location username2
2 dd/mm/yyy / hh:mm location username
我想要输出
TITLE DATE/TIME LOCATION USERNAME
=================================================
1 dd/mm/yyy / hh:mm location username, username1, username2
2 dd/mm/yyy / hh:mm location username
还是我需要把 foreach 放在echo '<td>' . array($r['username']) .'</td>';