|
|
|
Check All ผ่านตัวแปร Array ทำไงเหรอครับช่วยแนะนำด้วยครับ |
|
|
|
|
|
|
|
เอาตัวนี้ไปใช้ครับ ง่ายกว่า สั้นกว่าด้วย เหอ
<form action="#" name="check" method="post">
<input type="hidden" name="manage" value="delete">
<input type="checkbox" onClick="checkall()">all<br>
<? for($i=0;$i<=5;$i++){ $count++; ?>
<input type="checkbox" name="ch<?=$count;?>" value="Delete"><br>
<?
}
?>
<script Language="Javascript">
<!--
function checkall()
{
for (var j = 1; j <= <?=$count;?>; j++)
{
box = eval("document.check.ch" + j);
box.checked = !box.checked;
}
}
//-->
</script>
<input type="hidden" name="count" value="<?=$count;?>">
</form>
|
|
|
|
|
Date :
14 ก.พ. 2550 21:27:48 |
By :
arsachi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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>
เพิ่มเติมสำหรับการทำปุ่ม Check All
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<script language="JavaScript">
function ClickCheckAll(vol)
{
var i=1;
for(i=1;i<=document.frmMain.hdnCount.value;i++)
{
if(vol.checked == true)
{
eval("document.frmMain.chkDel"+i+".checked=true");
}
else
{
eval("document.frmMain.chkDel"+i+".checked=false");
}
}
}
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">
<input name="CheckAll" type="checkbox" id="CheckAll" value="Y" onClick="ClickCheckAll(this);">
</div></th>
</tr>
<?
$i = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$i++;
?>
<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[]" id="chkDel<?=$i;?>" value="<?=$objResult["CustomerID"];?>"></td>
</tr>
<?
}
?>
</table>
<?
mysql_close($objConnect);
?>
<input type="submit" name="btnDelete" value="Delete">
<input type="hidden" name="hdnCount" value="<?=$i;?>">
</form>
</body>
</html>
Screenshot
|
|
|
|
|
Date :
2009-10-18 07:54:16 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุนค่ะ มีประโยชน์มากๆเลย ทำให้โปรเจกผ่านไปด้วยดี
|
|
|
|
|
Date :
2011-05-05 21:09:16 |
By :
มิ้ม |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|