doutuosai3504 2014-11-04 19:18
浏览 114
已采纳

从php数组中删除逗号

I'm currently working on displaying some arrays using PHP and MySQL.

Simplified code looks like this:

$sql = "SELECT * FROM workorder";
$result = mysqli_query($dbc3,$sql);
$tryout_reports = array();
while ( $row = mysqli_fetch_assoc($result) ) {
   $tryout_reports[] = $row['file_name'] . "<br />";
}
$detail_report['tryout_reports'] = $tryout_reports;

I took a lot out of the SQL here, so if there's something wrong in there please don't mind. The SQL statement works fine.

The problem is it's being outputted with commas separating each value, and it's looking real bad.

The HTML on the page when run looks something like this:

File1.pdf <br>
","
File2.pdf <br>
","
etc..

Now, I've looked around quite a bit and i've tried the following:

ltrim()
rtrim()
explode()
str_replace()

I know rtrim works, but it doesn't remove the commas. I tried something like:

$tryout_reports[] = rtrim($row['file_name'],"pdf");

And it took the pdf out of the end of each one, but when I replace "pdf" with "," it does nothing.

Feeling really stuck, any help would be really appreciated!

Thanks

EDIT: Forgot to add, the page that uses this data and displays it on the page has this:

table.append("<tr><th>Tryout Reports </th><td>" + data[0].tryout_reports + "</td></tr>");

That is inside of a jQuery function which runs when a job number is clicked to display additional information.

  • 写回答

1条回答 默认 最新

  • douxie4583 2014-11-05 20:08
    关注

    That comma comes from javascript because you parse directly the array. You can use join: w3schools.com/jsref/jsref_join.asp

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改