Advertisement
cdsatrian

dynamic row-col

Apr 28th, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. <h3>Kolom dan baris tabel otomatis</h3>
  2. <table border="1" width="20px">
  3.   <tr><th>Nama Pegawai</th>
  4. <?php
  5. $jml_hari=date('t');
  6. for($i=1;$i<=$jml_hari;$i++){
  7.   echo "<th>$i</th>";
  8. }
  9. echo "</tr>\n";
  10. //-- konfigurasi database
  11. $dbhost='localhost';
  12. $dbuser='root';
  13. $dbpass='';
  14. $dbname='test';
  15. //---
  16. //$db=new mysqli($dbhost,$dbuser,$dbpass,$dbname);
  17. $db=mysql_connect($dbhost,$dbuser,$dbpass);
  18. mysql_select_db($dbname);
  19. $sql="SELECT nip,SUM(edc) AS jml,DAY(tanggal) AS tgl FROM divisi GROUP BY nip,tanggal ORDER BY nip,tanggal";
  20. //$result=$db->query($sql);
  21. $result=mysql_query($sql,$db);
  22. $nip='';
  23. //while($data=$result->fetch_object()){
  24. while($data=mysql_fecth_object($result)){
  25.   echo ($nip!=$data->nip?"<tr><td>{$data->nip}</td>":"");
  26.   for($i=1;$i<=$jml_hari;$i++){
  27.     echo ($i==$data->tgl?"<td>{$data->jml}</td>":"<td>&nbsp;</td>");
  28.   }
  29.   echo "</tr>\n";
  30. }
  31. ?>
  32. </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement