#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    36
    Rep Power
    15
    I would like to output the results of a select statement into a table with two columns. The first record will go in the first column, the second into the second, the third into the first, ....
    I'm totally confused as to how to do this.

    I could easily put them in a one column table but can't figure out the two columns:

    ONe column I would just use a while loop:

    $query = mysql_query("select * from news where condition=condition");
    while ($myrow = mysql_fetch_array($query)) {
    #put stuff into single column...
    }
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    Easy
    //set this to the number of columsn you want
    $cols = 2;

    //This is the counter
    $i =1
    $query = mysql_query("select * from news where condition=condition");

    print '<table><tr>';
    while ($myrow = mysql_fetch_array($query)) {
    if (is_int($i / $cols)) {
    print '<td>'.$myrow["somestuff"].'</td></tr><tr>';
    }
    else {
    print '<td>'.$myrow["somestuff"].'</td>';
    }
    $i++;
    }
    print '</tr></table>';

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    36
    Rep Power
    15
    Thanks. Just what I was looking for.

Similar Threads

  1. Replies: 1
    Last Post: February 17th, 2004, 06:25 PM
  2. Replies: 3
    Last Post: February 11th, 2004, 09:30 AM
  3. League table problem
    By silverduck in forum MySQL Help
    Replies: 8
    Last Post: February 10th, 2004, 01:38 PM
  4. Can anyone help with mysql query and results?
    By msmith29063 in forum MySQL Help
    Replies: 3
    Last Post: February 8th, 2004, 04:43 AM
  5. how to keep table on top, not centered??
    By vinyl in forum HTML Programming
    Replies: 2
    Last Post: January 20th, 2004, 07:19 PM

IMN logo majestic logo threadwatch logo seochat tools logo