Remove last comma or prevent it from being printed at all MySQL/PHP

前端 未结 3 437
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-24 10:36

I am printing a set of words that is placed in a MySQL database and I am retrieving it with PHP. I want to present it as a comma separated list, but I need it not to print or re

3条回答
  •  攒了一身酷
    2021-01-24 10:55

    I usually do this by placing the results in an array first

    $some_array = array();
    while($row0 = mysql_fetch_array($result0, MYSQL_ASSOC)) {
       $some_array[] = $row0['LCASE(ord)'];
    }
    

    then simply:

    echo "My List: " . implode(', ', $some_array);
    // Output looks something like:
    My List: ord1, ord2, ord3, ord4
    

提交回复
热议问题