View Single Post
Old 02-07-2004, 05:31 AM   #3 (permalink)
DonnChadh
Tilted
 
Location: Tha Boro
I've got a function like that, wrote it a few years back when I was still learning php, so it's probably not as optimised as it could be.

It does allow you to set the number of columns you want and distributes the items accordingly (adding empty cells if the final row isn't long enough)

It was originally designed for displaying a table of links, hence the m_items variable is a hash of url=name&...

PHP Code:
function TableMatrix($m_width$m_border$m_cols$m_items) {

 
$m_done "false";
 
$m_newcol "false";
 echo
"<table align=center width=$m_width border=$m_border>\n";

 
$m_split explode("&"$m_items);
 
$colcount 1;
 
$itemcount 0;
 
$m_totitem count ($m_split);

 while (
$m_done == "false") {

  if (
$itemcount $m_totitem) {
   
$temp $m_split[$itemcount];

   
$m_urlname explode("="$temp);
   if ((
$colcount == 1) && ($colcount != $m_cols)) {
     echo
"<tr>\n<td width=33%><a href='$m_urlname[0]' target='_blank'>$m_urlname[1]</a></td>\n";
     
$colcount++;
     
$m_newcol "false";
   }
   elseif (
$colcount $m_cols) {
     echo
"<td width=33%><a href='$m_urlname[0]' target='_blank'>$m_urlname[1]</a></td>\n";
     
$colcount++;
     
$m_newcol "false";
   }
   elseif (
$colcount == $m_cols) {
     echo
"<td width=33%><a href='$m_urlname[0]' target='_blank'>$m_urlname[1]</a></td>\n</tr>\n";
     
$colcount 1;
     
$m_newcol "true";
   }
   
$itemcount++;

  }
  elseif ((
$colcount <= $m_cols) && ($m_newcol == "false")) {
   while (
$colcount $m_cols) {
    echo
"<td width=33%>&nbsp;</td>\n";
    
$colcount++;
   }
   if (
$colcount $m_cols) {
    echo
"<td width=33%>&nbsp;</td>\n</tr>\n";
    
$m_done "true";
   }
  }
  else { 
$m_done "true"; }
 }

 echo
"</table>";

hmm, just noticed on here, that the td widths should probably calculated from the number of cols, oh well.
__________________
I try to take life one day at a time, but sometimes several days attack me at once.
DonnChadh is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73