SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: results in table

  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2011
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    results in table

    I have a query select all rounds where username = '$user'
    this is my code
    PHP Code:
    $result mysql_query("SELECT * FROM rounds WHERE username = '$user'");
            echo 
    "<table width='600' border='1'>
                    <tr>
                        <th>Course</th>
                        <th>Date Played</th>
                        <th>Par</th>
                        <th>Strokes</th>
                        <th>+/-</th>
                    </tr>"
    ;
                while (
    $row=mysql_fetch_array($result)) {
                    echo 
    "<tr>
                            <td align='center'>"
    ,$row['courseplayed'],"</td>
                            <td align='center'>"
    ,$row['dateplayed'],"</td>
                            <td align='center'>"
    ,$row['par'],"</td>
                            <td align='center'>"
    ,$row['score'],"</td>
                            <td align='center'></td>
                          </tr>
                         </table>"
    ;
                         ;}
                
    ?> 
    it pulls all the data correctly but only puts one of the results in the table the rest are under the table. What am I missing to get all the results in the table?

  2. #2
    Community Advisor silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    1,639
    Mentioned
    98 Post(s)
    Tagged
    4 Thread(s)
    Your closing TABLE tag is included in the 'while' loop; it gets printed each iteration.
    If you "View Source" on the output page you will see this.
    Move the closing 'table' tag to a single 'echo' statement at the end of this code and you will be in good shape.

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2011
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ParkinT View Post
    Your closing TABLE tag is included in the 'while' loop; it gets printed each iteration.
    If you "View Source" on the output page you will see this.
    Move the closing 'table' tag to a single 'echo' statement at the end of this code and you will be in good shape.
    Thanks ParkinT

Bookmarks

Posting Permissions

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