dongzhui9936 2019-01-11 10:45
浏览 46

用php删除表上的空行

I have table:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">

<table class="table-bordered" width="100%">

<tr>

<th>Product</th>
<th>Service</th>

</tr>
<tr>
<td>Product 1</td>
<td>S11</td>
</tr>
<tr>
<td></td>
<td>S13</td>
</tr>
<tr>
<td></td>
<td>S14</td>
</tr>
<tr>
<td>Product 2</td>
<td>S11</td>
</tr>
<tr>
<td></td>
<td>S120</td>
</tr>
</table>

I need: where empty row with product (where product's name is empty) delete this row and move service to up product row and delete current service from up product. Example:

In this table we have product 1. I need remove S11 and paste: S13 and S14 in single row.

I need this table on result:

    
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
    <table class="table-bordered" width="100%">

    <tr>

    <th>Product</th>
    <th>Service</th>

    </tr>
    <tr>
    <td>Product 1</td>
    <td>S13, S14</td>
    </tr>
    <tr>
    <td>Product 2</td>
    <td>S120</td>
    </tr>
    </table>

I know how it can do with javascript:

let tr;
$('#test1234 tr').each(function () {
 if($(this).find('td:nth-child(1)').text().length){
    tr = $(this);
    tr.find('td:nth-child(2)').text('')
 }else{
    let td = $(tr).find('td:nth-child(2)');
    let comma = td.text() !== "" ? ", " : '';
    td.text(td.text() +  comma +  $(this).find('td:nth-child(2)').text())
    $(this).remove()
 }

});

But I need do this with php. How I can do it? I have this html page on my php variable: $html_body.

</div>
  • 写回答

1条回答 默认 最新

  • doulan6150 2019-01-11 10:53
    关注

    generally you can't remove it using php but i will give you suggestion that please use continue statement when your row is blank

    for example

    $html = "<tbody>";
    
    foreach($data as $row){
        if(empty($row['parameter'])){
            continue;
        }else{
            $html .= "<tr> <td></td> </tr>";
        }
    }
    $html .= "</tbody>";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line