Results 1 to 5 of 5

Thread: While Loop in Table

  1. #1
    Join Date
    Jun 2009
    Posts
    62
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default While Loop in Table

    So I have a While Loop with my MySQL info.
    That makes a list of all my data but what if I want it to display in table with two columns? That way its in columns and not a list.
    If you need more explaination, ask.
    THANKS FOR THE HELP!!

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    write the <table> outside of the while and then this <tr><td></td><td></td></tr>inside then when the while closes </table> if you want more specific post your code or a sample of it
    Last edited by bluewalrus; 07-01-2009 at 09:56 PM. Reason: forgot a letter

  3. #3
    Join Date
    Jun 2009
    Posts
    62
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    Here's my code:
    PHP Code:
    $result mysql_query("SELECT * FROM videos ORDER BY title");

    while(
    $row mysql_fetch_array($result))
      {
      echo 
    "<a href='playvideo.php?videoid=" $row['videoid'] . "'>" $row['title'] . "</a>";
      echo 
    "<BR>";
      } 
    So how would I put into a table? I didn't really understand what you said.
    I want it so I have:
    title 1 | title 2
    title 3 | title 4
    title 5 | title 6
    as a table.

    THANKS!!

  4. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Something like this i think should do it

    Code:
    $result = mysql_query("SELECT * FROM videos ORDER BY title");
    ?>
    <table border = "0">
    <?php
    while($row = mysql_fetch_array($result))
      {
    ?>
    <tr><td><a href="playvideo.php?videoid=<?=$row['videoid']?>"><?=$row['title']?></a></td><td>TITLE 2 COMES FROM?</td></tr>
    <?php
      }  
    ?>
    </table>

  5. #5
    Join Date
    Jun 2009
    Posts
    62
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    Unfortunately, I tried that and it didn't work. If anyone wanted the answer though that I found, here it is:
    <table>
    PHP Code:
    $n 0;
    while (
    $row mysql_fetch_array($resultMYSQL_ASSOC))
    {
      if (
    $n == 0) {
        echo 
    '<tr>';
      }
      echo 
    "<td>DATA IN TABLE HERE</img></td>
    <td width=\"20px\"></td>\n"
    ;
      
    $n++;

      if (
    $n == 2) {
        echo 
    '</tr>';
        
    $n 0;
      }  

    }

    if (
    $n == 1) {
      echo 
    '<td></td>
    <td width=\"20px\"></td>
    </tr>'
    ;

    </table>

    -http://www.dmcinsights.com/phorum/read.php?9,39512

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
  •