How to group a column with PHP rowspan?

1

I need to make a rowspan inside a for

I have the following:

And the result I want to obtain is the following:

I've tried this but it does not work for me

<table id="tablaCS" class="table table-striped table-bordered">
<tr>
    <th colspan="3"></th>
</tr>
<tr>
    <th></th>
    <th>Org Account</th>
    <th>Total</th>
</tr>
<tr>
    <?php

    for ($i=0; $i < count($listadoMT_SMS_DATA["ORG_ACCOUNT"]) ; $i++) 
    { 
        if($listadoMT_SMS_DATA["ORG_ACCOUNT"][$i] == 'OtaDMC' or $listadoMT_SMS_DATA["ORG_ACCOUNT"][$i] == 'otarca1')
        {
            echo "<tr>
            <td></td>
            <td>".$listadoMT_SMS_DATA["ORG_ACCOUNT"][$i]."</td>
            <td><strong>".$listadoMT_SMS_DATA["TOTAL_MT"][$i]."</strong></td>
            </tr>";
        }
    }
    ?>
</tr>

    
asked by Juan Perez 03.12.2018 в 14:51
source

1 answer

1

You need to enter a condition in echo within for to enter rowspan .

<table id="tablaCS" class="table table-striped table-bordered">
<tr>
    <th colspan="3"></th>
</tr>
<tr>
    <th></th>
    <th>Org Account</th>
    <th>Total</th>
</tr>
<tr>
    <?php

    for ($i=0; $i < count($listadoMT_SMS_DATA["ORG_ACCOUNT"]) ; $i++) 
    { 
        if($listadoMT_SMS_DATA["ORG_ACCOUNT"][$i] == 'OtaDMC' or $listadoMT_SMS_DATA["ORG_ACCOUNT"][$i] == 'otarca1')
        {
            echo "<tr>";
            if($i==0) echo "<td rowspan=2></td>";                
            echo "<td>".$listadoMT_SMS_DATA["ORG_ACCOUNT"][$i]."</td>
            <td><strong>".$listadoMT_SMS_DATA["TOTAL_MT"][$i]."</strong></td>
            </tr>";
        }
    }
    ?>
</tr>

I've given you as an example the rowspan=2 for the example you gave and the condition $i=0 because this example is valid.

But if you need to group them in some way you will have to find a suitable condition and add the rowspan you want.

    
answered by 03.12.2018 в 15:15