1

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 Answer 1

3

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 } ?>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much for the idea. if(0==$i++) is to be used before column though. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.