|
 |
|
การใช้ checkbox ในการเลือกหรือไม่เลือกข้อมูลในฐานข้อมูล |
|
 |
|
|
 |
 |
|
เขียนให้แล้วครับ
Code (PHP)
<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.chkUpdate"+i+".checked=true");
}
else
{
eval("document.frmMain.chkUpdate"+i+".checked=false");
}
}
}
function onUpdate()
{
if(confirm('Do you want to update ?')==true)
{
return true;
}
else
{
return false;
}
}
</script>
<form name="frmMain" action="phpMySQLDeleteMultiRecord.php" method="post" OnSubmit="return onUpdate();">
<?
$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>
<input type="hidden" name="hdnCusID<?=$i;?>" id="hdnCusID<?=$i;?>" value="<?=$objResult["CustomerID"];?>">
<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="chkUpdate<?=$i;?>" id="chkUpdate<?=$i;?>" value="OK"></td>
</tr>
<?
}
?>
</table>
<?
mysql_close($objConnect);
?>
<input type="submit" name="btnUpdate" value="Update">
<input type="hidden" name="hdnCount" value="<?=$i;?>">
</form>
</body>
</html>
Code (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=1;$i<=$_POST["hdnCount"];$i++)
{
if($_POST["chkUpdate$i"] == "OK")
{
$strSQL = "UPDATE customer SET status = '2' ";
$strSQL .="WHERE CustomerID = '".$_POST["hdnCusID$i"]."' ";
$objQuery = mysql_query($strSQL);
}
else
{
$strSQL = "UPDATE customer SET status = '3' ";
$strSQL .="WHERE CustomerID = '".$_POST["hdnCusID$i"]."' ";
$objQuery = mysql_query($strSQL);
}
}
echo "Record Updated.";
mysql_close($objConnect);
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2010-11-23 11:42:42 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากนะค่ะ
|
 |
 |
 |
 |
Date :
2010-11-23 12:47:34 |
By :
tiya_13 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอรบกวนอีกเรื่องนะค่ะ
ถ้าเราจะแ่บ่งหน้าการแสดงผล จาก code ที่ได้ข้างต้น
จะต้องใส่ไว้ตรงไหนค่ะ
|
 |
 |
 |
 |
Date :
2010-11-23 14:08:51 |
By :
tiya_13 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|