Announcement

Collapse
No announcement yet.

New row once you get to a certain number of elements

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • New row once you get to a certain number of elements

    As the title suggests, I'm trying to figure out how to make a new row (in a table) once you get to a certain number of things. For example, say I had to pull 30 items out of the database, wanted them each in a cell, and wanted it to make a new row at the 15th cell. I have this feeling I'm missing something ridiculously obvious, but I can't seem to figure it out. Can anyone help? Thanks

    - Silver

  • #2
    Well, you use a counter to count up each time.

    PHP Code:
    // ....
    $x 1;
    while(
    $row mysql_fetch_array($query)) {
        if(
    $x == 15) {
            echo 
    "</tr><tr>";
            
    $x 1;
        }

        echo 
    "<td>$row[mydata]</td>";
        
    $x++;

    Thats about how I do it

    Comment


    • #3
      Works like a charm. Many thanks

      Comment

      widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
      Working...
      X