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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    row table placement

    I want to output my data into a three-column table, but I do not understand where to place my HTML tables or if I need additional coding.

    With the following example, the results contain duplicates:
    PHP Code:
        $query "SELECT * FROM customers"
        
    $result mysql_query($query);
    echo 
    "<table width='600' border='1' cellspacing='4' cellpadding='0'>";
      while (
    $row mysql_fetch_array($result))
      {
         
    extract($row);
    echo 
    "    <tr>
            <td>Hi, my name is $name and I'm $age years old.</td>
            <td>Hi, my name is $name and I'm $age years old.</td>
            <td>Hi, my name is $name and I'm $age years old.</td>
        </tr>"
    ; }
    echo 
    "</table>"
    // Desired Table Format
    +--------+--------+--------+
    +--------+--------+--------+
    +--------+--------+--------+

  • #2
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    PHP Code:
    $result mysql_query('SELECT * FROM customers') or exit(mysql_error());
    while (
    $row mysql_fetch_assoc($result)) {$array[] = $row;}
    $chunks array_chunk($array3);

    echo 
    '<table width="600" border="1" cellspacing="4" cellpadding="0">';
    foreach (
    $chunks as $value)
    {
        echo 
    '<tr>';
        foreach (
    $value as $row) {echo '<td>Hi, my name is ' $row['name'] . ' and I\'m ' $row['age'] . ' years old</td>';}
        echo 
    '</tr>';
    }
    echo 
    '</table>'


  •  

    Posting Permissions

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