Posted By

level09 on 04/27/09


Tagged

php display column


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

vali29
ReeceMarsland


PHP Display Arrays in Columns


 / Published in: PHP
 

  1. function column_display($items,$numcols) {
  2.  
  3. $numitems = count($items);
  4.  
  5. // Number of Rows
  6. $numrows = ceil($numitems/$numcols);
  7.  
  8. $output = '<table>';
  9. for ($row=1; $row <= $numrows; $row++)
  10. {
  11. $cell = 0;
  12. $output .= ' <tr>'."\n";
  13. for ($col=1; $col <= $numcols; $col++)
  14. {
  15. $output .= ' <td>'."\n";
  16.  
  17. if ($col===1)
  18. {
  19. $cell += $row;
  20.  
  21. $output .= $items[$cell - 1]->name;
  22.  
  23. }
  24. else {
  25. $cell += $numrows;
  26. $output .= $items[$cell - 1]->name;
  27. }
  28. $output .= ' </td>'."\n";
  29. }
  30. $output .= ' </tr>'."\n";
  31. }
  32. $output .= '</table>';
  33. return $output;
  34. }

Report this snippet  

You need to login to post a comment.