Sepating MySQL result set into html tables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux