Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //file fungsi.inc.php
- <?php
- function koneksi_db(){
- $dbhost="localhost";
- $dbuser="root";
- $dbpasw="";
- $dbname="latihan";
- $link=mysql_connect($dbhost,$dbuser,$dbpasw);
- mysql_select_db($dbname,$link);
- }
- function delete_row($table,$field,$value){
- $sql="DELETE FROM $table WHERE $field='$value'";
- $ret=mysql_query($sql);
- return $ret;
- }
- function get_data($table,$fields){
- $sql="SELECT ".fields." FROM ".$table;
- return mysql_query($sql);
- }
- koneksi_db();
- ?>
- //file prodi.php
- <?php
- include("fungsi.inc.php");
- if(!empty($_GET['id'])){
- delete_row('prodi','kd_prodi',$_GET['id']);
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Latihan Fungsi Delete Baris</title>
- </head>
- <body>
- <table width="200" border="1">
- <tr>
- <td>Prodi</td>
- <td>Nama</td>
- <td>Delete</td>
- </tr>
- <?php
- $q=get_data('prodi','kd_prodi,prodi');
- while($k=mysql_fetch_array($q)){
- echo "<tr>\n";
- echo "<td>".$k['kd_prodi']."</td>\n";
- echo "<td>".$k['prodi']."</td>\n";
- echo "<td><a href=\"".$SERVER['PHP_SELF']."?id=".$k['kd_prodi']."\">hapus</a></td>\n";
- echo "</tr>\n";
- };
- ?>
- </table>
- </body>
- </html>
- //file mata_kuliah.php
- <?php
- include("fungsi.inc.php");
- if(!empty($_GET['id'])){
- delete_row('mata_kuliah','kd_mk',$_GET['id']);
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Latihan Fungsi Delete Baris Mata Kuliah</title>
- </head>
- <body>
- <table width="200" border="1">
- <tr>
- <td>Kode Mata Kuliah</td>
- <td>Mata Kuliah</td>
- <td>Delete</td>
- </tr>
- <?php
- $q=get_data('mata_kuliah','kd_mk,mata_kuliah');
- while($k=mysql_fetch_array($q)){
- echo "<tr>\n";
- echo "<td>".$k['kd_mk']."</td>\n";
- echo "<td>".$k['mata_kuliah']."</td>\n";
- echo "<td><a href=\"".$SERVER['PHP_SELF']."?id=".$k['kd_mk']."\">hapus</a></td>\n";
- echo "</tr>\n";
- };
- ?>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement