Skip to content
View in the app

A better way to browse. Learn more.

Komuniti @PuTeRA

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Delete Rows Dalam Database..dengan Checkbox

Featured Replies

Salam semua..sorry kalau soalan macam budak2
Dah google abes, still stuck. Harap ade yang kat sini boleh bantu. :)

Aku ade buat satu sistem, data sume blh masuk database
Tapi masalahnye bile nak delete..
Aku nak die blh show sume data tu, then ade checkbox yg kita boleh tanda
Then tekan butang delete, data tu hilang
Maknanya boleh delete beberapa row/data dalam satu masa..

Nih gambar die:

http://www.diigo.com/item/image/1aptd/xe8p

Coding yang aku pakai plak:

[CODE]

<?php
$host="localhost"; // Host name
$username="skem"; // Mysql username
$password="skem"; // Mysql password
$db_name="skem"; // Database name
$tbl_name="admin"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mysql</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Lastname</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Email</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['P_Id']; ?>"></td>
<td bgcolor="#FFFFFF"><? echo $rows['P_Id']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['username']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['password']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['usertype']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td>
</tr>
<?
// Check if delete button active, start this
if($delete){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM $tbl_name WHERE id='$del_id'";
$result = mysql_query($sql);
}
// if successful redirect to delete_multiple.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=aduseradd.php\">";
}
}
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>
[/CODE]

Coding nih based ape yang aku jumpe kat http://www.phpeasystep.com/mysql/8.html

Harap ade sape2 yang expert tuh, bantu la ea. Thanks in advance :)
  • 3 weeks later...
[php]

if(isset($_POST['delete'])) {

$checkbox = $_POST['checkbox'];

for($i=0;$i<count($checkbox);$i++) {

$del_id = $checkbox[$i];
$sql = "DELETE FROM $tbl_name WHERE id='$del_id'";
$result = mysql_query($sql);

}

[/php]
  • 2 weeks later...
Hope Working... Code not test yet..

[CODE]
if(isset($_POST['delete'])) {

$id_array= $_POST['checkbox'];

$id = implode(" ",$id_array);

$sql = "DELETE FROM $tbl_name WHERE id IN(".$id.")";

$result = mysql_query($sql);
}


[/CODE]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.