Hi. I've been searching the forum for the answer and cannot find it, although I am certain I am not the first to experience this.
I am displaying the results of a query, with each item having a comma added to it so that a proper list appears. I think I may have outsmarted myself, as I cannot figure out the logic needed to print the comma on all but the last entries. I know it's a simple solution, but my mind is stuck in a rut.
My thinking is that as long as the counter is less than the total number of results, it will add a comma. As soon as it reaches the total number, it will not add the comma. Here is the code:
while($row = mysqli_fetch_array($cont_result,MYSQLI_BOTH))
{
for($ccc = 1; $ccc <= $num_rows; $ccc++)
{
if($ccc<$num_rows)
{
echo $row['name'] . ', ';
} else {
echo $row['name'];
}
}
}
Thanks.