SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to split rows in two column...

    Hello,

    How can i split rows from mysql in two column, if i have for exmpl. 20 rows i need to print them 10 in one col. and another 10 in seconde column.
    If there is for exmpl. 15 rows i would like to print 10 in one column and 5 in seconde.

    I'm spliting table using td so i have:

    <td>
    first column
    </td>
    <td>
    sec. column
    </td>
    Thank you very much...

  2. #2
    SitePoint Guru Ruben K.'s Avatar
    Join Date
    Jun 2005
    Location
    Alkmaar, The Netherlands
    Posts
    693
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something similar to this:

    PHP Code:
    $i 0;
    while( 
    $r mysql_fetch_assoc$result ) )
    {
        
    // whatever you want to do here
        
    echo'<td>content</td>';

        
    // now watch this
        
    if( $i )
        {
            echo 
    '</tr><tr>';
            
    $i 0;    
        }
        else
        {
            
    $i++;
        }

    That'd do the trick. Change the if $i > 0 part to a bigger number for more columns per row.

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It works great!! Tank you very much !!!

  4. #4
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    take a look here for improved flexibility: http://www.sitepoint.com/forums/showthread.php?t=272624
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.


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
  •