Skip to content

Commit

Permalink
+ [Snippets] printTable.php - print table from array
Browse files Browse the repository at this point in the history
  • Loading branch information
roytam1 committed Mar 28, 2008
1 parent 6ef268f commit 1699c03
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions Snippets/printTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
function printTable($ary,$colmax=3) {
$out='<table><tr>';
$col=0;
foreach($ary as $k => $v) {
$out.='<td><b>'.$k.':</b></td><td>'.$v.'</td>';
if((++$col%$colmax)==0) $out.='</tr><tr>';
}
return $out.'</tr></table>';
}

function printTableWithHeader1($act,$ary=null) {
switch($act) {
case 'new':
$out='<table border="1" cellpadding="0" cellspacing="0"><tr>';$out2='';
foreach($ary as $k => $v) {
$out.='<th>'.$k.'</th>';
$out2.='<td>'.$v.'</td>';
}
return $out.'</tr><tr>'.$out2.'</tr>';
break;
case 'cont':
$out='<tr>';
foreach($ary as $k => $v) {
$out.='<td>'.$v.'</td>';
}
return $out.'</tr>';
break;
case 'end':
return '</table>';
break;
}
}

function printTableWithHeader2($ary='end') {
static $firstrun = true;
if($firstrun) {
$firstrun = false;
$out='<table border="1" cellpadding="0" cellspacing="0"><tr>';$out2='';
foreach($ary as $k => $v) {
$out.='<th>'.$k.'</th>';
$out2.='<td>'.$v.'</td>';
}
return $out.'</tr><tr>'.$out2.'</tr>';
} elseif($ary=='end') {
$firstrun = true;
return '</table>';
} else {
$out='<tr>';
foreach($ary as $k => $v) {
$out.='<td>'.$v.'</td>';
}
return $out.'</tr>';
}
}

0 comments on commit 1699c03

Please sign in to comment.