The problem with your code is that you are doing everything within your while-loop. Focus the removal of the last coma outside your loop. There are 100s of different ways of doing what you're trying to achieve. One easy way is to just remove the last character of your string (since it's always a coma, right?). Try just doing it like this:
$query1 = mysql_query("SELECT b_id FROM benefits");
while ($row = mysql_fetch_array($query1)) {
$b_id .= $row['b_id'] . ",";
}
substr($b_id,0,-1);
That should remove the last coma, you can however do this in many other ways as I said earlier.