I am just a beginner in php. I used the following code to display the user names fetched from the database.
$select_tl = "SELECT `varTeamleader` FROM `tbl_team` WHERE `intTeamid` = '" . $id . "'";
$select_tl_res = mysql_query($select_tl);
$select_tl_num = mysql_num_rows($select_tl_res);
if ($select_tl_num > 0) {
$fetch_tl = mysql_fetch_array($select_tl_res);
$tl = $fetch_tl['varTeamleader'];
$sep_tl = explode(",", $tl);
foreach ($sep_tl as $key => $value) {
$sel_tlname = "SELECT * FROM `tbl_user` WHERE `intUserid` = '" . $value . "'";
$sel_tlname_res = mysql_query($sel_tlname);
$sel_tlname_num = mysql_num_rows($sel_tlname_res);
if ($sel_tlname_num > 0) {
$fetch_username = mysql_fetch_array($sel_tlname_res);
$user_name = $fetch_username['varName'];
echo $user_name . ", ";
}
}
}
I need to echo the user_name with comma after every value but not after last one. How can i do that?
Add the items to an array and then
implode(',', $arr).