timmah1 Posted February 5, 2009 Share Posted February 5, 2009 I have a query that pulls some information out of the database <?php $q1 = mysql_query("SELECT * FROM subCat WHERE mainID = '$id' ORDER BY name LIMIT 5"); while ($b1 = mysql_fetch_array($q1)) { echo "<span class='page_content1'><a href='business.php?id=$b1[id]&main$main'>$b1[name]</a></span>"; ?> It works with no problem, but how would I take the 5 results and seperate them with a comma, with the last one not have a comma? Right now it's like this text1 texxt2 text3 text4 text5 But how do I get it to look like this text1, texxt2, text3, text4, text5 Thanks in advance Link to comment https://forums.phpfreaks.com/topic/143878-solved-probably-simple/ Share on other sites More sharing options...
trq Posted February 5, 2009 Share Posted February 5, 2009 <?php $q1 = mysql_query("SELECT * FROM subCat WHERE mainID = '$id' ORDER BY name LIMIT 5"); while ($b1 = mysql_fetch_array($q1)) { $out .= "<span class='page_content1'><a href='business.php?id=$b1[id]&main$main'>$b1[name]</a></span>,"; } echo rtrim($out, ','); ?> Link to comment https://forums.phpfreaks.com/topic/143878-solved-probably-simple/#findComment-754964 Share on other sites More sharing options...
timmah1 Posted February 5, 2009 Author Share Posted February 5, 2009 I knew it would be something simple. Thanks again thorpe Link to comment https://forums.phpfreaks.com/topic/143878-solved-probably-simple/#findComment-754966 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.