1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Output to 3 columns

Discussion in 'PHP' started by billybrag, Feb 18, 2006.

  1. #1
    Hi again :)

    I have a list that is generated from my mysql db and i would like to output it into 3 equal columns on the page?

    is that possible? how would i approach it?

    Thanks

    Mike
     
    billybrag, Feb 18, 2006 IP
  2. Lordo

    Lordo Well-Known Member

    Messages:
    2,082
    Likes Received:
    58
    Best Answers:
    0
    Trophy Points:
    190
    #2
    Sure. Here is a quick approach:
    You have the data outputting loop, right? You will put:
    <table>
    before the loop and
    </table>
    after it.
    And add a counter to be used as a row reference.
    Now the loop will look like this:

    <table>
    <?
    $i = -1;
    while($rs=mysql_assoc($result)){
    $i++;
    if($i/3 == intval($i/3)){
    ?>
    <tr>
    <?
    }
    // Now echo the db row 
    
    
    if(($i+1)/3 == intval(($i+1)/3)){
    ?>
    </tr>
    <?
    }
    }
    ?>
    </table>
    PHP:
     
    Lordo, Feb 18, 2006 IP
  3. HN Will

    HN Will Guest

    Messages:
    111
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Perhaps I'm not seeing it correctly, but I believe their should be some <td></td> tags in there to allow the three columns

    Something to the effect of:

    <table>
    <tr>
    <td>
    (1/3 MySQL data)
    </td>
    <td>
    (1/3 MySQL data)
    </td>
    <td>
    (1/3 MySQL data)
    </td>
    </tr>
    </table>

    is this more what you were going for?
     
    HN Will, Feb 18, 2006 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    jestep, Feb 18, 2006 IP
  5. Lordo

    Lordo Well-Known Member

    Messages:
    2,082
    Likes Received:
    58
    Best Answers:
    0
    Trophy Points:
    190
    #5
    Yes, <td> goes inside the loop, thanks for your note.

    <table>
    <?
    $i = -1;
    while($rs=mysql_assoc($result)){
    $i++;
    if($i/3 == intval($i/3)){
    ?>
    <tr>
    <?
    }
    ?>
    <td>
    <?
    // Now echo the db row   
    
    ?>
    </td>
    <?
    if(($i+1)/3 == intval(($i+1)/3)){
    ?>
    </tr>
    <?
    }
    }
    ?>
    </table>
    PHP:
     
    Lordo, Feb 18, 2006 IP