Reputation: 1
So I am selecting values from database and they are like
and I am displaying the values on the site like
but it is not counting how much values are selected and it is inserting one comma in the last value expecting one more value to come.
This is the php code:
<?php
while ($row2 = mysqli_fetch_assoc($result_t)): ?>
<?php echo $row2['tipo'] . ", ";?>
<?php endwhile;?>
Upvotes: 0
Views: 70
Reputation: 1
Implode the values (you will need to check how implode works Link here) with a comma (,)
Upvotes: 0
Reputation: 1274
You can get all the values from the DB in an array and then call implode() to join the individual values using comma.
Upvotes: 0
Reputation: 1269753
Use group_concat()
in MySQL:
select group_concat(tipo) as tipos
from t;
Upvotes: 2