doutingyou2198
doutingyou2198
2012-04-09 19:16
浏览 38
已采纳

表rowspan问题

I have the following table. The header is at it looks and the content is generated within a PHP loop. It contains some taxes that a user has to pay and a tax can be paid in installments. For example, if the user has to pay a 100$ tax and he first pays 25$ and then 75$, there will be two rows in the table for that tax.

What I seem to fail to accomplish is to make a rowspan so the tax name will be displayed only once.

Any help is appreciated.

<table cellpadding="0" cellspacing="0" width="100%" class="sortable">
    <thead>
        <tr>                                                        
            <th width="10%">Tax name</th>
            <th width="10%">Value</th>
            <th width="10%">Paid</th>
            <th width="10%">Rest</th>            
        </tr>
    </thead>
    <tbody>
        <tr>                                    
            <td>Sign-up tax</td>
            <td>100$</td>
            <td>25$</td>
            <td>75$</td>                        
        </tr>   
        <tr>                                    
            <td>Sign-up tax</td>
            <td>100$</td>
            <td>75$</td>
            <td>0$</td>                        
        </tr>
    </tbody>
</table>

The PHP code looks like this:

<?php for ($i = 0; $i < count($tax_details); $i++): ?>
<tr>                                    
    <td><?php echo $tax_details[$i]['name']; ?></td>
    <td><?php echo $tax_details[$i]['value']; ?></td>
    <td><?php echo $tax_details[$i]['paid']; ?></td>
    <td><?php echo $tax_details[$i]['rest']; ?></td>                        
</tr>
<?php endfor; ?>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • donglian8407
    donglian8407 2012-04-09 19:18
    已采纳

    replace the html with this:

    <tbody>
        <tr>                                    
            <td rowspan="2">Sign-up tax</td>   <---add rowspan here
            <td>100$</td>
            <td>25$</td>
            <td>75$</td>                        
        </tr>   
        <tr>                                    
            <td>100$</td>         <---remove second sign-up tax from here
            <td>75$</td>
            <td>0$</td>                        
        </tr>
    </tbody>
    
    点赞 评论
  • doulun1939
    doulun1939 2012-04-09 19:28

    Your code looks correct, I don't see the problem.

    <table border="0" cellpadding="0" cellspacing="0" width="100%" class="sortable">
        <thead>
            <tr>                                                        
                <th width="10%">Tax name</th>
                <th width="10%">Value</th>
                <th width="10%">Paid</th>
                <th width="10%">Rest</th>            
            </tr>
        </thead>
    <tbody>
    <?php for ($i = 0; $i < count($tax_details); $i++): ?>
    <tr>                                    
        <td><?php echo $tax_details['name']; ?></td>
        <td><?php echo $tax_details['value']; ?></td>
        <td><?php echo $tax_details['paid']; ?></td>
        <td><?php echo $tax_details['rest']; ?></td>                        
    </tr>
    <?php endif; ?>
        </tbody>
    </table>
    

    I fail to understand what you are asking.

    点赞 评论

相关推荐