SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Displaying for loop data in columns

    hey all how can i echo a simple list of values in columns like
    1 2 3 4 5 6 7 8 9 10
    for now i m using this code but instead of horizontal displaying its showing vertical. as i m new to php
    Code PHP:
    <?php
    for ($i=1; $i<=20; $i++)
      {
      echo "<table>
      <tr>" .$i."<br/>".
      "</tr>
      </table>";
      }
    ?>
    All those who wander aren't lost.

  2. #2
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is an HTML question really. Anyway:

    PHP Code:
    <table>
    <tr>
    <?php
    for ($i=1$i<=20$i++) {
        echo 
    "<td>{$i}</td>";
    }
    ?>
    </tr>
    </table>

  3. #3
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    why did the <table> tag fall out b4 php starting and why not inside?
    All those who wander aren't lost.

  4. #4
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because if you put the table tag inside the loop you will end up with a table per each iteration of the loop. What you want is a cell per iteration of the loop.

    I think you need to get up to speed with HTML and then dive into PHP.


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
  •