SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    May 2006
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using PHP output MySQL query into table with two columns

    So i have a database which has a bunch of info which i need to ouput into a table with two columns!

    The info in the database is listed in on big long table (one column with multiple rows) and in alpabetical order! Because the table is sooooo long I want to split it into two columns (or three if possible)!

    I haven't a clue as to how to go about this!! Any help would be very appreciated!
    -Thanks!

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,609
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    When you are looping through the result simply set a counter and when it reaches a certain value reset it and start a new column. (Nest each column as a table within an outer table).

    <table>
    <tr>
    <td><table for column 1></td>
    <td><table for column 2></td>
    <td><table for column 3></td>
    </tr>
    </table>
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    defined a counter $counter

    print "<tr>"";
    while ( )
    {
    $counter++ //incremenet it
    print "<td>$data</td>"
    if($counter%3==0) // to display in 3 columns

    {
    print "</tr><tr>"'
    }
    }

    This is a rough sketch what you have to do

  4. #4
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,609
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That will give you alphabetic left-to-right, down, left-to-right, etc.

    A B C
    D E F
    G H I

    My proposal gives you alphabetic down, right, down, right, down etc.

    A D G
    B E H
    C F I

    (Both equally valid proposals, depending on what the OP actually needs).
    Ian Anderson
    www.siteguru.co.uk


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
  •