Advertisement
rimsky82

php- timestable(html out) -better

Dec 3rd, 2011
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.54 KB | None | 0 0
  1. function getTable($hstart, $hmax, $hstep, $vstart, $vmax, $vstep){
  2.     //do the column header row
  3.         $out = "<table><tbody><tr>";
  4.         for($h=$hstart-$hstep;$h<=$hmax;$h+=$hstep)
  5.             $out .= ($h==$hstart-$hstep) ? "<th></th>" : "<th>".$h."</th>";
  6.         $out .= "</tr>";
  7.     //do the rest
  8.         for($i=$vstart;$i<=$vmax;$i+=$vstep){
  9.             //throw in the row header
  10.             $out .= "<tr><th>".$i."</th>";
  11.             //do the math
  12.             for($j=$hstart;$j<=$hmax;$j+=$hstep)
  13.                 $out .= "<td>".$i*$j."</td>";
  14.             $out .= "</tr>";
  15.         }
  16.         $out .= "</tbody></table>";
  17.         return $out;
  18. }
  19.  
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement