|
|
|
การลบข้อมูลโดยใช้ checkbox เลือกหลายๆ recode ใครพอจะมีตัวอย่างหรือแนวทางบ้างคะ ตัวอย่างเหมือนเราลบ email ใน hotmail |
|
|
|
|
|
|
|
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<form action="PageMultiCheckbox2.php" method="post" name="form1">
Please select color.<br>
<input type="checkbox" name="chkColor[]" value="Red">Red<br>
<input type="checkbox" name="chkColor[]" value="Blue">Blue<br>
<input type="checkbox" name="chkColor[]" value="Green">Green<br>
<input type="checkbox" name="chkColor[]" value="Orange">Orange<br>
<input type="checkbox" name="chkColor[]" value="Black">Black<br>
<input name="btnSubmit" type="submit" value="Submit">
</form>
</body>
</html>
=============================
PageMultiCheckbox2.php
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<?
for($i=0;$i<count($_POST["chkColor"]);$i++)
{
if(trim($_POST["chkColor"][$i]) != "")
{
echo "chkColor $i = ".$_POST["chkColor"][$i]."<br>";
}
}
?>
</body>
</html>
|
|
|
|
|
Date :
18 ส.ค. 2551 21:54:09 |
By :
@W_IN |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
phpMySQLDeleteMultiRecordList.php
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<script language="JavaScript">
function onDelete()
{
if(confirm('Do you want to delete ?')==true)
{
return true;
}
else
{
return false;
}
}
</script>
<form name="frmMain" action="phpMySQLDeleteMultiRecord.php" method="post" OnSubmit="return onDelete();">
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM customer";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Used </div></th>
<th width="30"> <div align="center">Delete </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center"><?=$objResult["CustomerID"];?></div></td>
<td><?=$objResult["Name"];?></td>
<td><?=$objResult["Email"];?></td>
<td><div align="center"><?=$objResult["CountryCode"];?></div></td>
<td align="right"><?=$objResult["Budget"];?></td>
<td align="right"><?=$objResult["Used"];?></td>
<td align="center"><input type="checkbox" name="chkDel[]" value="<?=$objResult["CustomerID"];?>"></td>
</tr>
<?
}
?>
</table>
<?
mysql_close($objConnect);
?>
<input type="submit" name="btnDelete" value="Delete">
</form>
</body>
</html>
Screenshot
phpMySQLDeleteMultiRecord.php
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
for($i=0;$i<count($_POST["chkDel"]);$i++)
{
if($_POST["chkDel"][$i] != "")
{
$strSQL = "DELETE FROM customer ";
$strSQL .="WHERE CustomerID = '".$_POST["chkDel"][$i]."' ";
$objQuery = mysql_query($strSQL);
}
}
echo "Record Deleted.";
mysql_close($objConnect);
?>
</body>
</html>
Ref : PHP MySQL Multiple Checkbox Delete Record
|
|
|
|
|
Date :
2009-10-15 23:56:24 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|