php中的动态rowspan while循环

问题描述 投票:2回答:1

我需要通过数据库中的值来实现这样的结果:

------------------------------------------------------------------------
Question                                                 Marks
------------------------------------------------------------------------
Question 1                                       |
-------------------------------------------------|
Question 2                                       |         5
-------------------------------------------------|
Question 3                                       |

但是当我喜欢这样的时候:

<?php
    while ( $PQRr = mysql_fetch_array($PQRq) ) {
?>
<tr>
    <td align="center"><?php echo $PQRr["point_title"]; ?></td>
    <td align="center" rowspan="5">
        <?php echo $marks_obtained; ?>
    </td>
</tr>
<?php } ?>

它实际上打印了查询执行的最后一列次数。我怎样才能打印一次?

这是我目前得到的。

php html mysql html-table rows
1个回答
4
投票

试试这个。现在该部分只执行一次。

  <?php
            $i=0;
            while ( $PQRr = mysql_fetch_array($PQRq) ) {
            ?>
            <tr>
                <td align="center"><?php echo $PQRr["point_title"]; ?></td>
                <td align="center" rowspan="5">
                    <?php if(0==$i++) {echo $marks_obtained;} ?>
                </td>
            </tr>
            <?php } ?>
© www.soinside.com 2019 - 2024. All rights reserved.