Pertemuan 8 - Report Tabel

1,058 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,058
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
19
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Pertemuan 8 - Report Tabel

  1. 1. Report: Tabel Adi Triyatmoko, S.Kom. Prak. Sistem Basis Data Pertemuan Ke 8 Sistem Informasi Rabu, 12 Mei 2010
  2. 2. Tujuan <ul><ul><li>Koneksi ke MySQL </li></ul></ul><ul><ul><li>Melakukan Query dalam PHP </li></ul></ul><ul><ul><li>Hiasan Tabel warna </li></ul></ul><ul><ul><li>Query untuk Pencarian </li></ul></ul>Report: Tabel Halaman 2
  3. 3. Koneksi ke MySQL <ul><ul><li>Melakukan sambungan koneksi ke dalam database MySQL menggunakan Sintaks PHP. </li></ul></ul><ul><ul><li>mysql_connect() </li></ul></ul><ul><li>attempts to establish a connection to a MySQL database engine running on host </li></ul><ul><ul><li>Sintaks: </li></ul></ul><ul><li>mysql_connect(char host, char user, char pass) </li></ul>Report: Tabel Halaman 3
  4. 4. Report: Tabel Halaman 4 <?php $hostname = &quot;localhost&quot;; $username= &quot;root&quot;; $password = &quot;&quot;; $connect = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR); $database = “kuliah”; mysql_select_db($database, $connect) or die(&quot; database tidak ditemukan&quot;); ?> config.php
  5. 5. Melakukan Query dalam PHP <ul><ul><li>Executes the SQL statement. the string must consist of a single SQL statement and you should not add a terminating semicolon (“;”). </li></ul></ul><ul><ul><li>mysql_query() </li></ul></ul><ul><ul><li>Sintaks: </li></ul></ul><ul><li>int mysql_query(char *statement_string) </li></ul><ul><ul><li>Return Values (int): </li></ul></ul><ul><li>Zero if the statement was successful. Nonzero if an error occurred. </li></ul>Report: Tabel Halaman 5
  6. 6. Report: Tabel Halaman 6 <?php require_once('config.php'); $query = &quot;select * from mhs&quot;; $meta = mysql_query($query, $koneksi) or die(mysql_error()); while($hasil=mysql_fetch_array($meta)) { echo “Nama : $hasil[namamhs] <br>”; echo “Nim : $hasil[nim] <br><br>”; } ?> tabel.php
  7. 7. Bentuk Tabel Report: Tabel Halaman 7 <?php require_once('config.php'); $query = &quot;select * from mhs&quot;; $meta = mysql_query($query, $connect) or die(mysql_error()); echo &quot;<table border=“1&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot;> &quot;; echo &quot;<tr><td>No</td><td>Nama</td><td>Alamat</td></tr> &quot;; while($hasil = mysql_fetch_array($meta)) { echo &quot;<tr><td>$hasil[nim]</td> <td>$hasil[namamhs]</td> <td>$hasil[alamat]</td></tr>&quot;; } echo &quot;</table>&quot;; ?> tabel2.php
  8. 8. Report: Tabel Halaman 8 <html><head> <style> .tabeldata { border: 1px solid #909090; font-size : 12px } .judul { font-weight: bold; text-align: center; background: #C0C0C0 } .terang { background: #E8E8E8 } .gelap { background: #D8D8D8 } .sorot { background: #E6B016 } </style> </head> <body> <?php require_once('config.php'); $query = &quot;select * from mhs&quot;; $meta = mysql_query($query, $connect) or die(mysql_error()); echo &quot;Tabel Mahasiswa&quot;; $terang = true; echo &quot;<table border=&quot;0“ cellspacing=&quot;1“ cellpadding=&quot;3“ class=&quot;tabeldata&quot;> &quot;; echo &quot;<tr class=&quot;judul&quot;><td>Nim</td><td>Nama</td><td>Alamat</td></tr> &quot;; tabel3.php
  9. 9. Report: Tabel Halaman 9 while($hasil = mysql_fetch_array($meta)) { if ($terang) { echo &quot;<tr class=&quot;terang&quot; onMouseOver=&quot;this.className='sorot'&quot; onMouseOut=&quot;this.className='terang'&quot;>&quot;; } else { echo &quot;<tr class=&quot;gelap&quot; onMouseOver=&quot;this.className='sorot'&quot; onMouseOut=&quot;this.className='gelap'&quot;>&quot;; } echo &quot;<td align=&quot;center&quot;>&quot; . $hasil[nim] . &quot;</td>&quot; . &quot;<td>&quot; . $hasil[namamhs] . &quot;</td>&quot; . &quot;<td>&quot; . $hasil[alamat] . &quot;</td></tr> &quot;; $terang = !$terang; } echo &quot;</table> &quot;; ?> </body></html>
  10. 10. Query Pencarian <ul><ul><li>Metode pencarian dengan menginput Nama lalu melakukan query “like” kedalam database. </li></ul></ul><ul><ul><li>File yang dibuat: </li></ul></ul><ul><li>Form Input Nama. </li></ul><ul><li>Hasil Query. </li></ul>Report: Tabel Halaman 10
  11. 11. Report: Tabel Halaman 11 <html> <head> <body> <form action=&quot;hasilcari.php&quot; method=&quot;get&quot;> <label>Masukkan pencarian Nama : </label> <input name=&quot;nama&quot; /> <br> <input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Cari&quot; /> </body> </html> formcari.php
  12. 12. Report: Tabel Halaman 12 <?php require_once('config.php'); $query = &quot;select * from mhs where namamhs like '%$_GET[nama]%'&quot;; $meta = mysql_query($query, $connect) or die(mysql_error()); echo &quot;Nama: $_GET[nama]&quot;; echo &quot;<table border=&quot;1&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot;> &quot;; echo &quot;<tr><td>Nim</td><td>Nama</td><td>Alamat</td></tr> &quot;; while($hasil = mysql_fetch_array($meta)) { echo &quot;<tr><td>$hasil[nim]</td> <td>$hasil[namamhs]</td> <td>$hasil[alamat]</td></tr>&quot;; } echo &quot;</table>&quot;; ?> hasilcari.php
  13. 13. Terima Kasih Informasi Lengkap: My Blog Aladiw.us

×