如果我有一个包含项目的数据库表以及该项目的错误,例如:
Car Scratch
Car Dent
Car Rust
Bike Broken light
Bike Rust
如何在HTML表格中以下列格式显示:
Car Scratch, Dent, Rust
Bike Broken light, Rust
以HTML格式插入HTML表格:
<tr>$name(Car)</tr>
<tr>$defects(scratch, dent, rust)</tr>
答案 0 :(得分:1)
您可以更新您的mysql查询,使用您的类别选择您的item_name,就像您的要求一样
SELECT tank_no, GROUP_CONCAT(ng_id) as item_name FROM non_green GROUP BY `tank_no`;
这是您的最终查询
var href = @Url.Action("SingleSentShow","Home", new { msgId ="__msgID__" ,receiverId="__receiverID__" });
href = href.replace("__mgsID__",obj[i].senderId).replace("__receiverID__",obj[i].senderId);
$tbl.append(' <tr><td> <a href="' + href + '">' + '... the rest of your line');
其中类别是汽车,自行车等,项目是划痕,凹痕,锈迹
因此,当您选择此项时,您可以打印category和item_name,无需在php部分处理。检查此附件
您还可以查看更多详细信息 How to use GROUP BY to concatenate strings in MySQL?