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 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python