Advertisement
cdsatrian

latihan fungsi delete baris

Jun 21st, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. <?php
  2. $dbhost="localhost";
  3. $dbuser="root";
  4. $dbpasw="";
  5. $dbname="latihan";
  6. $link=mysql_connect($dbhost,$dbuser,$dbpasw);
  7. mysql_select_db($dbname,$link);
  8.  
  9. function delete_row($table,$field,$value){
  10.     $sql="DELETE FROM $table WHERE $field='$value'";
  11.     $ret=mysql_query($sql);
  12.     return $ret;
  13. }
  14. if(!empty($_GET['id'])){
  15.     delete_row('prodi','kd_prodi',$_GET['id']);
  16. }
  17. ?>
  18. <!DOCTYPE html>
  19. <html>
  20. <head>
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  22. <title>Latihan Fungsi Delete Baris</title>
  23. </head>
  24. <body>
  25.   <table width="200" border="1">
  26.     <tr>
  27.       <td>Prodi</td>
  28.       <td>Nama</td>
  29.       <td>Delete</td>
  30.     </tr>
  31. <?php
  32.     while($k=mysql_fetch_array($q)){
  33.         echo "<tr>\n";
  34.         echo "<td>".$k['kd_prodi']."</td>\n";
  35.         echo "<td>".$k['prodi']."</td>\n";
  36.         echo "<td><a href=\"".$SERVER['PHP_SELF']."?id=".$k['kd_prodi']."\">hapus</a></td>\n";
  37.         echo "</tr>\n";
  38.     };
  39. ?>
  40.   </table>
  41. </body>
  42. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement