user1433995
user1433995

Reputation:

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

Upvotes: 1

Views: 3872

Answers (1)

Poorya Mohammadi
Poorya Mohammadi

Reputation: 751

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

Upvotes: 3

Related Questions