php - Problems with echoing array values -
i having trouble echoing values array. using mysql query create array, $online
, containing names of online users. here code:
<?php $goodbye = time() - 300; $qry="select username members seen >=$goodbye"; $result=mysql_query($qry); if($result) { $online = mysql_fetch_assoc($result); foreach($online $u) { echo $u; echo "<br>"; } } else { die("query failed"); } ?>
when viewing on web page, first index of array shown (as in: if user1, user17, , user69 online, user1 appear on list). i'm sure happening because i'm using echo incorrectly, haven't been able figure out yet. tips? thanks.
you should loop (mysql_fetch_assoc)
if($result) { while ($row = mysql_fetch_assoc($result)) { echo $row["username"]; } }
also, notice warning
.
Comments
Post a Comment