dqyym3667
2015-02-01 12:16 阅读 38
已采纳

php中的动态rowspan while循环

I need to achieve a result like this through the values in database:

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

but when I do like this:

<?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 } ?>

It actually prints the the last column number of times query executes. How can I make it print just one time?

Here's what I am getting currently. http://awesomescreenshot.com/0074b9wy01

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dongzao9044 dongzao9044 2015-02-01 12:29

    Try this. Now that part will only be executed once.

      <?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 } ?>
    
    点赞 评论 复制链接分享

相关推荐