drn1008 2016-03-26 11:30
浏览 49
已采纳

如何在从mysql中取出的记录之间放一个逗号而不是结束或开始php

I want to put a comma in between the numbers I pull out of the database , but when I do it , it sometimes put the comma at the end and beginning which I don’t like

I want the numbers to be = 44123123123,44188123123,44123123123

Not = , 44123123123,44188123123,44123123123 Or = 44123123123,44188123123,44123123123,

I have tried everything but no luck . please help see also Bellow is what I have tried

$comma =",";
while($record = $targe1->fetch(PDO::FETCH_ASSOC)){
$cell = $record['cell'] ;
$company = $record['company'];
$surname = $record['surname'];

    $final_cell1 = explode(",",$record['cell']);

$final_cell = implode(",",$final_cell1).$comma;


echo $final_cell;

 }

I am writing a script which sends sms it pulls out numbers and names then it sends . the bulk sms plug in for sending many sms at once , it requires the numbers to be separated by a comma and if there is a comma at the begging or end it ignores and no sms will be sent . any help will be appreciated .

  • 写回答

2条回答 默认 最新

  • dsfs23434 2016-03-26 11:34
    关注

    To remove the last comma you just need substr()

    Try this:

    while ($record = $targe1->fetch(PDO::FETCH_ASSOC)) {
        /* Other code */
        $cell .= $record['cell'].',';
     }
    
    $cell= substr($cell,0,-1);
    

    Hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式