简体   繁体   中英

Dynamic rowspan in php while loop

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM