#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 Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    MO, US
    Posts
    119
    Rep Power
    15
    The script below works for multiple columns.
    Go to www.cityzip.com and click on a state to see the example.

    $connection = mysql_connect("localhost", "root") or die ("Couldn't connect to the server.");
    $db = mysql_select_db("Your Database", $connection) or die ("Couldn't select database.");
    $sql = "SELECT * FROM yourtablename WHERE var1 = '$val1' ORDER BY var1 ASC";
    $result = mysql_query($sql,$connection) or die ("couldn't execute query.");

    //Set this to be the number you want across
    $rows = 5;
    $i = 1;
    echo '<table width="650" align="center"><tr>';
    while ($row = mysql_fetch_array($result)) {
    if (is_int($i / $rows)) {
    echo '<td width="20%" align="center"><font size=-1>';
    echo '<A HREF=';
    echo $row["field name 1"];
    echo '>';
    //Next echo and field name not necessarily needed
    echo $row["field name 2"];
    echo '</A></td></font></tr><tr>';
    }
    else {
    echo "<td width='20%' align='center'><font size=-1>";
    echo '<A HREF=';
    echo $row["field 1"];
    echo '>';
    echo $row["field 2"];
    echo "</A></td></font>";
    }
    $i++;
    }
    echo '</tr></table>';
    echo "</P>

Similar Threads

  1. League table problem
    By silverduck in forum MySQL Help
    Replies: 8
    Last Post: February 10th, 2004, 01:38 PM
  2. remove two columns from a table
    By gordie in forum MySQL Help
    Replies: 2
    Last Post: January 25th, 2004, 12:58 PM
  3. how to keep table on top, not centered??
    By vinyl in forum HTML Programming
    Replies: 2
    Last Post: January 20th, 2004, 07:19 PM
  4. Replies: 1
    Last Post: January 20th, 2004, 02:39 PM
  5. select from table with parameter from another
    By PHPme in forum MySQL Help
    Replies: 9
    Last Post: January 14th, 2004, 09:26 PM

IMN logo majestic logo threadwatch logo seochat tools logo