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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Posts
    311
    Thanks
    0
    Thanked 1 Time in 1 Post

    structuring a table in a while loop

    I have the following code that needs to be lined up sid by side like below:

    3 3 3
    3 3 3
    3 3 3

    I can't seem to figure out how to get it done

    Here is the code:

    PHP Code:
    <?PHP 
    $query 
    mysql_query("Select * from franks_puzzles") or trigger_error(mysql_error());
    $i=0;
    while(
    $row mysql_fetch_array($query)){ 
    ?>

    <table border="1" width = "100">
      <tr>
        <th scope="col"><img src="images/<?php echo $row['image']; ?>" width ="100" ></th>
      </tr>
      <tr>
        <td><?php echo $row['name']; ?></td>
      </tr>
      <tr>
        <td><?php echo $row['desc']; ?></td>
      </tr>
    </table>

    <? $i++;  }

    ?>

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    You need to take the table outside of the while loop. Do it like this. Copy this

    Code:
    <?PHP 
    $query = mysql_query("Select * from franks_puzzles") or trigger_error(mysql_error());
    $i=0;
    <table border="1" width = "100">
    while($row = mysql_fetch_array($query)){ 
    ?>
    
    
      <tr>
        <th scope="col"><img src="images/<?php echo $row['image']; ?>" width ="100" ></th>
      </tr>
      <tr>
        <td><?php echo $row['name']; ?></td>
      </tr>
      <tr>
        <td><?php echo $row['desc']; ?></td>
      </tr>
    
    
    <? $i++;  }
    </table>
    
    ?>

  • #3
    Regular Coder
    Join Date
    Aug 2006
    Posts
    311
    Thanks
    0
    Thanked 1 Time in 1 Post
    That still does not work. It still gives me the pattern

    1
    1
    1
    1
    1
    1
    1

    This need to be

    3 3 3
    3 3 3
    3 3 3

    anyone

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    use mysql_fetch_assoc instead of mysql_fetch_array.

    regards
    Last edited by oesxyl; 07-23-2008 at 09:15 AM.

  • #5
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    PHP Code:
    <?PHP 
    $query 
    mysql_query("Select * from franks_puzzles") or trigger_error(mysql_error());
    $i=0;
    echo 
    '<table border="1" width = "100">';
    while(
    $row mysql_fetch_assoc($query)){ 
    ?>
      <tr>
        <th scope="col"><img src="images/<?php echo $row['image']; ?>" width ="100" ></th>
        <td><?php echo $row['name']; ?></td>
        <td><?php echo $row['desc']; ?></td>
      </tr>
    <?php $i++;  }
    echo 
    '</table>';
    ?>
    dumpfi
    "Failure is not an option. It comes bundled with the software."
    ....../)/)..(\__/).(\(\................../)_/)......
    .....(-.-).(='.'=).(-.-)................(o.O)...../<)
    ....(.).(.)("}_("}(.)(.)...............(.)_(.))Ż/.
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
    Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

  • #6
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Ah yeah there was too many <tr> tags. <tr> means to break a line down. Where <td> means to be side by side. So you only need 1 <tr> opening and closing tag.


  •  

    Posting Permissions

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