Sepating MySQL result set into html tables
| From: | Thodoris | Date: | Fri, 26 Sep 2008 16:56:59 +0000 |
| Subject: | Sepating MySQL result set into html tables | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-280995@lists.php.net to get a copy of this message | ||
Hello everybody,
I have a mysql result set that I want to print out in an html table. But some times it gets so big that I will probably need to separate it in to multiple ones. I wrote a function that separates the result set into three ones like this:
function showTable($columnNames,$data,$alignment,$wrap) {
$limit = round(count($data)/3,0);
$align = array('l'=>'align="left"','c'=>'align="center"','r'=>'align="right"');
$table = "<table class='inner'>";
$table .= "<table><tr><td><table class='inner'>";
$table .= "<tr>";
foreach ($columnNames as $col_name){
$table .= "<th>".$col_name."</th>";} $table .= "</tr>\n"; foreach ($data as $j => $row) {
if(($j % 2) == 0){
$table .= "<tr class=even>";
} else {
$table .= "<tr class=odd>";
}
for($i=0;$i<count($row);$i++){
$table .= "<td ".$wrap." ".$align[$alignment[$i]].">".$row[$i]."</td>";
}
$table .= "</tr>\n";
if (($j == $limit-1) || ($j == (2*$limit)-1)) {
$table .= "</table></td><td><table>";
$table .= "<tr>";
foreach ($columnNames as $col_name){
$table .= "<th>".$col_name."</th>";
}
$table .= "</tr>\n";
}
}
$table .= '</table></td></tr>';
$table .= "</table>\n";
print $table;
}
But I really need to tell the function in how many tables I need the result set to be separated. How can I do this?
What can I put instead of this for 3 tables: (($j == $limit-1) || ($j == (2*$limit)-1))
I can't find the algorithm although I think I have done this before but I can't remember how.
--
Thodoris