Jump to content

[SOLVED] Lists and Commas


steveangelis

Recommended Posts

I have created a simple PHP list and after each item I have a comma.  I am unsure though how to have it so that after the query posts the last item it does not have a comma at the end.  Here is my code:

 

while($rowd = mysql_fetch_array($qrd)) {
$qrd2= mysql_query("select * from dpt where id=".$rowd['dpt_id']);
$rrd2 = mysql_fetch_array($qrd2);
echo $rrd2['name'].", ";
}

Those code is nothing fancy but I am unsure to have the last item not have a trailing comma.  Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/169510-solved-lists-and-commas/
Share on other sites

$Content = "";

while($rowd = mysql_fetch_array($qrd)) {
$qrd2= mysql_query("select * from dpt where id=".$rowd['dpt_id']);
$rrd2 = mysql_fetch_array($qrd2);
$Content .= $rrd2['name'].", ";
}
$Content = substr_replace($string ,"",-1);
echo $Content;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.