GWibisono

ternyata kerapian itu perlu

Oct 29th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.65 KB | None | 0 0
  1. <title>Query 4, menghitung rata-rata</title>
  2. <h2>Query 4 Menghitung Rata-rata nilai dari Query Tabel Users</h2>
  3. <style type="text/css">
  4. table {
  5.   font: 12px/24px Verdana, Arial, Helvetica, sans-serif;
  6.   border-collapse: collapse;
  7.   width: 500px;
  8.   margin:0 auto;
  9. }
  10. th {
  11.   border: 1px solid #CCC;
  12.   padding: 0 0.5em;
  13.   text-align: center;
  14.   background-color:#00FF66
  15. }
  16. td {
  17.   border: 1px solid #CCC;
  18.   padding: 0 0.5em;
  19.   background-color:#DFFDD5;
  20. }
  21. h1 {
  22.   color:#003300;
  23.   font:22px "Trebuchet MS";
  24.   text-align:center;
  25. }
  26. </style>
  27. <table border="1" width="500px">
  28. <tr>
  29. <th>No</th>
  30. <th>Nama Anak</th>
  31. <th>Rata-rata Skor</th>
  32. <th>Rata-rata Waktu</th>
  33. <th>Petunjuk</th>
  34. </th>
  35.  
  36. <!-- example 1 :menampilkan data di tabel-->
  37. <?php
  38. error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
  39. $batas=30; //satu halaman menampilkan 30 baris
  40. $halaman=$_GET['halaman'];
  41. $posisi=null;
  42. if(empty($halaman)){
  43.     $posisi=0;
  44.     $halaman=1;
  45. }else{
  46.     $posisi=($halaman-1)* $batas;
  47. }
  48.  
  49. //===============START HERE=================
  50. require_once('include/koneksi.php');
  51. $sql="SELECT soal1,soal2,soal3,soal4,soal5,soal6,soal7,soal8,soal9, (soal1 + soal2 + soal3 +
  52. soal4 + soal5 + soal6 + soal7 + soal8 + soal9)/9  as avgtotal,
  53. username, waktu1,petunjuk1
  54. FROM users";
  55. $result=mysql_query($sql) or die(mysql_error());
  56.  
  57. $no=1; //penomoran
  58.  
  59. while($rows=mysql_fetch_object($result))
  60. {
  61. ?>
  62.      
  63.      <td><?php echo $no; ?></td>
  64.      <td><?php echo $rows->username;?></td>
  65.      <td><?php echo $rows->avgtotal;?></td>
  66.      <td><?php echo $rows->waktu1;?></td>
  67.      <td align='right'><?php   
  68. echo $rows->petunjuk1;?></td>
  69.      </tr>
  70. <?php
  71.  
  72. $no++;
  73. }
  74. ?>
  75. </table>
Advertisement
Add Comment
Please, Sign In to add comment