Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Retriving more than one row in php from mysql

    I am making a table for the results of my quiz and i need help getting each row in a different table row. heres my code:

    PHP Code:
    while ($rows=mysql_fetch_array($results)) {
    echo 'name: '.$Name.'&nbsp;<br>';
    echo 'score: '.$Score.'&nbsp;<br>';
    echo 'question 1: '.$q1.'&nbsp;<br>';
    echo 'question 2: '.$q2.'&nbsp;<br>';
    echo 'question 3: '.$q3.'&nbsp;<br>';
    echo 'question 4: '.$q4.'&nbsp;<br>';
    echo 'question 5: '.$q5.'&nbsp;<br>';
    echo 'question 6: '.$q6.'&nbsp;<br><br><br>';


    $Name = $rows['name'];
    $Score = $rows['score'];
    $q1 = $rows['question_1'];
    $q2 = $rows['question_2'];
    $q3 = $rows['question_3'];
    $q4 = $rows['question_4'];
    $q5 = $rows['question_5'];
    $q6 = $rows['question_6'];

    }
    ?>
    </p>
    <table align='center' border='1' bordercolor='black'>
    <tr>
    <td align='center'>Name:</td>
    <td align='center'>Score: </td>
    <td align='center'>? #1</td>
    <td align='center'>? #2</td>
    <td align='center'>? #3</td>
    <td align='center'>? #4</td>
    <td align='center'>? #5</td>
    <td align='center'>? #6</td>
    </tr>


    <tr>
    <td align='center'><?php echo $Name?>&nbsp;&nbsp;</td>
    <td align='center'><?php echo $Score?>&nbsp;&nbsp;</td>
    <td align='center'><?php echo $q1?>&nbsp;&nbsp;</td>
    <td align='center'><?php echo $q2?>&nbsp;&nbsp;</td>
    <td align='center'><?php echo $q3?>&nbsp;&nbsp;</td>
    <td align='center'><?php echo $q4?>&nbsp;&nbsp;</td>
    <td align='center'><?php echo $q5?>&nbsp;&nbsp;</td>
    <td align='center'><?php echo $q6?>&nbsp;&nbsp;</td>
    </tr>

    </body>
    </html>
    Hey y'all check my web site

  • #2
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try re-arranging your code a bit...:

    PHP Code:
    <?php ?>
    </p>
    <table align='center' border='1' bordercolor='black'>
    <tr>
    <td align='center'>Name:</td>
    <td align='center'>Score: </td>
    <td align='center'>? #1</td>
    <td align='center'>? #2</td>
    <td align='center'>? #3</td>
    <td align='center'>? #4</td>
    <td align='center'>? #5</td>
    <td align='center'>? #6</td>
    </tr>

    <?php
     
    while ($rows=mysql_fetch_array($results)) {

    echo 
    "<tr>
       <td align='center'>{$rows['name']}&nbsp;&nbsp;</td>
       <td align='center'>{$rows['score']}&nbsp;&nbsp;</td>
       <td align='center'>{$rows['question_1']}&nbsp;&nbsp;</td>
       <td align='center'>{$rows['question_2']}&nbsp;&nbsp;</td>
       <td align='center'>{$rows['question_3']}&nbsp;&nbsp;</td>
       <td align='center'>{$rows['question_4']}&nbsp;&nbsp;</td>
       <td align='center'>{$rows['question_5']}&nbsp;&nbsp;</td>
       <td align='center'>{$rows['question_6']}&nbsp;&nbsp;</td>
    </tr>"
    ;

    }
    ?>
    </body>
    </html>

  • #3
    New Coder
    Join Date
    Aug 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks

    Thank you that helped alot and it displayed my data right
    Hey y'all check my web site


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •