I have a query that gets a list of online members from the database. <?php $main .= '<div class="t1"> '; while( $activeArray=mysql_fetch_array($activeQuery) ) { $main .= '<a href="./index.php?member=' . $activeArray['mid'] . '">' . $activeArray['username'] . '</a> (' . $activeArray['location'] . ') '; }$main .= ' </div> '; ?> PHP: How do I make that part which displays the results separate each user with a comma but not put a comma after the last result?
My php is rusty but you'll most likely want to use the join() function. It joins elements in an array into a single string with each item separated by whatever is in the quotes. Something like this: join(", ", $array) Code (markup):
<?php $elements = array(); while( $activeArray=mysql_fetch_array($activeQuery) ) { $elements[] = '<a href="./index.php?member=' . $activeArray['mid'] . '">' . $activeArray['username'] . '</a> (' . $activeArray['location'] . ') '; } $main = '<div class="t1">' . implode(', ', $elements) . '</div>'; ?> PHP: