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

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?