displaying single column data in multiple columns

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • erp23
    New Member
    • Aug 2007
    • 26

    displaying single column data in multiple columns

    This might seem like a problem with a simple solution, but I'm not entirely sure how to approach it.

    I would like to generate a user contact list from a table of user details on a database. However, for the master page (which only needs to display the name), I was wondering if there is any way that the user names could be displayed in multiple rows rather than one continuous vertical stream (I would rather avoid recordset paging).

    I suppose you could do it horizontally by outputting each record in a css block element one third of the total div width, but I would rather do it in a vertical direction ie you go down, then start at the top and once again for a 3 column list.

    Any pointers in the right direction would be appreciated.
  • kovik
    Recognized Expert Top Contributor
    • Jun 2007
    • 1044

    #2
    ?

    Maybe... a table...?

    Comment

    • erp23
      New Member
      • Aug 2007
      • 26

      #3
      sorry, maybe I wasn't clear enough -

      yes, I could use a table, but what I'm not sure is how to do the looping structure in order to go down vertically ie

      Item 1 - Item 4 - Item 7
      Item 2 - Item 5 - Item 8
      Item 3 - Item 6 - Item 9

      Presumably you need some sort of auto-increment counter to decide where to draw <tr> and <td>? Or create two divs and assign recordsets to $col1 $col2 and $col3?

      My main problem is that the total number of contacts can vary, so the number per column will be the total no. of contacts / 3...

      Is this possible or should I just try and go for a horizontal order
      Item1 - Item 2 - Item3 etc
      ?

      Comment

      • kovik
        Recognized Expert Top Contributor
        • Jun 2007
        • 1044

        #4
        [php]echo '<table><tr>';
        $i = 0;

        while($data = mysql_fetch_obj ect($result))
        {
        $i++;

        if(($i % 3) == 0)
        {
        $i = 0;
        echo '</tr><tr>';
        }

        echo '<td>' . $data->foo . '</td>';
        }

        echo '</tr></table>';[/php]

        Maybe?

        Comment

        • erp23
          New Member
          • Aug 2007
          • 26

          #5
          yes, that's along the lines of what I'm looking for - wasn't quite sure about the exact syntax with counter divisions, but adapting this has worked. thanks.

          Comment

          Working...