Echo a comma on all but the last value? (result from mysql_fetch_array)

后端 未结 11 2029
隐瞒了意图╮
隐瞒了意图╮ 2020-12-21 22:56

How do I echo a comma on all but the last value? Here\'s my code:

while ($servdescarrayrow = mysql_fetch_array($servdescarray)) {

    ECHO $servdescarrayrow         


        
11条回答
  •  北荒
    北荒 (楼主)
    2020-12-21 23:34

    $out = $mydb->getOne("SELECT group_concat(serv_desc) FROM table");
    

    where $mydb is a database class, getOne() is a helper function returning first col of the first row and group_concat() output is limited to 1024 bytes but can be altered by setting appropriate variable.

    But of course an average enthusiast from this site will always use generic PHP for such a task, as nobody will tell him there are more intelligent ways.

提交回复
热议问题