|
 |
|
เรื่อง checkbox เลือกทั้งหมด คือต้องการทำคล้ายๆๆ hotmail ค่ะ คือเลือกทั้งหมด เอาออกทั้งหมด ตอนนี้ทำได้เร้ว |
|
 |
|
|
 |
 |
|
ในส่วนของ Checkbox ที่มันส่งค่าหลาย ๆ ตัวนั้นมันจะส่งในลักษณะที่เป็นประมาณนี้นะครับ
$checkbox => 1,2,3,4,5
เวลารับก็
$arrPara = explode(',',$checkbox);
แล้วก็เอาค่า $arrPara มาใช้งานได้ในรูปแบบของ Array ได้แล้วครับ อะไรประมาณนี้ล่ะครับ
ถ้ายังไม่ได้ก็ติดต่อมาอีกทีนะครับ
|
 |
 |
 |
 |
Date :
2009-05-14 12:00:40 |
By :
artorigin7 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังทำไม่ได้เลยค่ะ คือหน้าที่รับค่า
$checkbox => 1,2,3,4,5 // ที่คุณบอกคืออชื่อตัวแปรใน form checkbox หรือ ชือ type หรอ เร้วต้องรับแบบไหน GET หรือ POST ลองแล้วยังไม่ได้ ไม่แน่ใจว่าเราเข้าใจผิดตรงไหนป่าว
เวลารับก็
$arrPara = explode(',',$checkbox);
ขอคนที่รู้ แนะนำด้วยนะ ขอบคุณค่ะ
|
 |
 |
 |
 |
Date :
2009-05-14 17:27:03 |
By :
pp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พิมพ์ตก
Code (PHP)
<?php
echo "<input type=\"checkbox\" name=\"ch[]\" value=\"" . $rows["id"] . "\">";
?>
|
 |
 |
 |
 |
Date :
2009-05-14 22:15:27 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณนะค่ะ ทำได้แล้วว งมโข่งตั้งนาน
|
 |
 |
 |
 |
Date :
2009-05-15 04:29:27 |
By :
pom |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณ คุณ PlaKriM มากค่ะ
กำลังหาอยู่พอดีเลย
|
 |
 |
 |
 |
Date :
2009-10-14 15:10:00 |
By :
I_aM_jib |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
น่าสนจัยครับ ต้องหัดใช้งาน checkbox มั้งแล้ว ขอบคุณครับผม
|
 |
 |
 |
 |
Date :
2009-10-14 22:57:31 |
By :
puthaiii |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
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 08:00:20 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|