Advertisement
cdsatrian

Dynamic Columns/Rows

Sep 6th, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.61 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <title>Dynamic Column</title>
  5.   </head>
  6.   <body>
  7.     <table border="1">
  8.       <tr>
  9.       <?php
  10.       $data=array('satu','dua','tiga','empat','lima','enam','tujuh','delapan');
  11.       $jml_data=count($data);
  12.       $jml_kolom=4;
  13.       $sisa=$jml_data%$jml_kolom;
  14.       $i=0;
  15.       while($jml_data)
  16.       {
  17.         echo ($i%$jml_kolom==0&&$i!=0?"</tr><tr>":"")."<td>{$data[$i]}</td>";
  18.         $i++;
  19.         $jml_data--;
  20.       }
  21.       if($sisa)
  22.         for($i=1;$i<$sisa;$i++)
  23.           echo "<td>&nbsp;</td>";
  24.       ?>
  25.       </tr>
  26.     </table>
  27.   </body>
  28. </htmL>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement