|
|
|
ต้องการใช้ checkbox ในการลบข้อมูล และสามารถเลือกทั้งหมดได้ ในการลบ |
|
|
|
|
|
|
|
ขอบคุณมากคะ
|
|
|
|
|
Date :
2015-11-14 02:38:14 |
By :
jkchilla02 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2015-11-14 07:29:45 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เอาครอบโค๊ดหน่อยครับ
|
|
|
|
|
Date :
2015-11-15 18:45:41 |
By :
NewbiePHP |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#หน้า phpMySQLDeleteMultiRecord.php
Code (PHP)
<?php
$objConnect = mysql_query($query_rs_em, $con_leaveonline) or die(mysql_error());
$objDB = mysql_select_db($database_con_leaveonline, $con_leaveonline);
for($i=0;$i<count($_POST["chkDel"]);$i++)
{
if($_POST["chkDel"][$i] != "")
{
$strSQL = "DELETE FROM employee ";
$strSQL .="WHERE em_id = '".$_POST["chkDel"][$i]."' ";
$objQuery = mysql_query($strSQL);
}
}
echo "Record Deleted.";
mysql_close($objConnect);
?>
#หน้า ad_profile_employee.php
Code (PHP)
<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>
<table width="955" align="center">
<tr>
<td colspan="2"><img src="images/head.jpg" width="955" height="265" /></td>
</tr>
<tr>
<td width="195" height="262" valign="top">
<div align="left">
<table>
<tr>
<td width="187"><a href="ad_permission.php"><img src="images/manu7ad.png" width="187" height="41" border="0" /></a></td>
</tr>
<tr>
<td><img src="images/manu9ad.png" width="187" height="41" /></td>
</tr>
<tr>
<td><a href="ad_data_employee.php"><img src="images/manu8ad.png" width="187" height="41" border="0" /></a></td>
</tr>
<tr>
<td><a href="ad_logout.php"><img src="images/manu5.png" width="187" height="41" border="0" /></a></td>
</tr>
</table>
</div>
<p align="left"> </p> <p align="left"> </p></td>
<td width="756" valign="top"><div align="center" class="style3">
<p>ประวัติลางานของพนักงาน</p>
<form name="frmMain" action="phpMySQLDeleteMultiRecord.php" method="post" OnSubmit="return onDelete();">
<table width="677" border="1">
<tr>
<td width="205"><div align="center">ชื่อ</div></td>
<td width="231"><div align="center">นามสกุล</div></td>
<td width="219"><div align="center">รายละเอียดการลา</div></td>
<td width="219"><div align="center">
<input name="CheckAll" type="checkbox" id="CheckAll" value="Y" onClick="ClickCheckAll(this);">
</div></td>
</tr>
<?php
$i = 0;
$i++;
//ตรวจสอบว่ามีข้อมูลหรือไม่
if ($row_rs_em != 0) {
do { ?>
<tr>
<td height="64"><?php echo $row_rs_em['em_name']; ?></td>
<td><?php echo $row_rs_em['em_surname']; ?></td>
<td valign="top"><div align="center"><a href="ad_profile_detail.php?em_id=<?php echo $row_rs_em['em_id']; ?>"><img src="images/icon/Search-Images-icon.png" width="60" height="60" border="0" /></a></div></td>
<td valign="middle"><div align="center">
<input type="checkbox" name="chkDel[]" id="chkDel<?php echo $i;?>" value="<?php echo $row_rs_em["em_id"];?>" />
</div></td>
</tr>
<?php } while ($row_rs_em = mysql_fetch_assoc($rs_em)); ?>
<tr>
<td height="10" colspan="4"><div align="center" class="style4">
<input type="submit" name="btnDelete" value="Delete">
<input type="hidden" name="hdnCount" value="<?php echo $i;?>">
</div></td>
</tr>
<?php
} else { // ถ้าไม่มีที่เลือก?>
<tr>
<td height="11" colspan="4"><div align="center"><span class="style4">ไม่มีข้อมูล</span></div></td>
</tr>
<?php } ?>
</table>
</form>
</div></td>
</tr>
</table>
<?php
mysql_close($objConnect);
?>
<p> </p>
</body>
</html>
<?php
mysql_free_result($rs_em);
mysql_free_result($rs_emle);
?>
|
|
|
|
|
Date :
2015-11-15 19:42:38 |
By :
jkchilla02 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผลลัพธ์
มี 4 ข้อมูลที่จะลบนะคะ เมื่อติ๊ก checkbox จะลบ 1 ข้อมูลนะคะ แล้วกดลบข้อมูลที่เลือก กลับขึ้นหน้าเหมือนลบข้อมูลออกไปหมด
แต่พอเข้ามาดูข้อมูลอีกทีนึง กลับเลือก 3 รายการ แล้วถูกลบไป 1
อยากให้เวลาลบ 1 แล้วกลับมาหน้าเดิม แล้วเหลือ 3 ข้อมูลอะคะ
ช่วยดูโค้ดหน่อยนะคะ
หน้า ad_profile_detail.php
Code (PHP)
<form id="form2" name="form1" method="post" action="ad_del_detail.php">
.
.
.
<input type="checkbox" name="cbdel[]" id="cbdel" value="<?php echo $row_rs_emle['le_id']; ?>"/>
....
....
<input type="submit" name="cmddel" id="cmddel" value="ลบรายการที่เลือก" />
หน้า ad_del_detail.php
Code (PHP)
<?php require_once('Connections/con_leaveonline.php'); ?>
<?php
// ส่งค่ามาจากปุ่ม ยืนยันลบรายการสินค้า
if (isset($_POST["cmddel"])) {
$i=0;
//ตรวจสอบค่าที่มาจาก checkbox
while($i<count($_POST['cbdel']))
{
$catid = $_POST['cbdel'][$i];
mysql_select_db($database_con_leaveonline, $con_leaveonline);
$query_rs_emle = "DELETE FROM employeele WHERE le_id = '$catid'";
$rs_emle = mysql_query($query_rs_emle, $con_leaveonline) or die(mysql_error());
$i++;
}
@mysql_free_result($rs_emle);
header("Location: " . "ad_profile_detail.php");
}
?>
|
|
|
|
|
Date :
2015-11-17 11:47:55 |
By :
jkchilla02 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
นี้คือโค้ดทั้งหมดของหน้า ad_profile_detail.php
Code (PHP)
<?php require_once('Connections/con_leaveonline.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$colname_rs_emle = "-1";
if (isset($_GET['em_id'])) {
$colname_rs_emle = $_GET['em_id'];
}
mysql_select_db($database_con_leaveonline, $con_leaveonline);
$query_rs_emle = sprintf("SELECT * FROM employeele WHERE em_id = %s", GetSQLValueString($colname_rs_emle, "int"));
$rs_emle = mysql_query($query_rs_emle, $con_leaveonline) or die(mysql_error());
$row_rs_emle = mysql_fetch_assoc($rs_emle);
$totalRows_rs_emle = mysql_num_rows($rs_emle);
$colname_rs_emle1 = "-1";
if (isset($_GET['le_id'])) {
$colname_rs_emle1 = $_GET['le_id'];
}
mysql_select_db($database_con_leaveonline, $con_leaveonline);
$query_rs_emle1 = sprintf("SELECT * FROM employeele WHERE le_id = %s", GetSQLValueString($colname_rs_emle1, "int"));
$rs_emle1 = mysql_query($query_rs_emle1, $con_leaveonline) or die(mysql_error());
$row_rs_emle1 = mysql_fetch_assoc($rs_emle1);
$totalRows_rs_emle1 = mysql_num_rows($rs_emle1);
$colname_rs_emle = "-1";
if (isset($_GET['em_id'])) {
$colname_rs_emle = $_GET['em_id'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>LeaveOnline System</title>
<style type="text/css">
<!--
body {
margin-top: 0px;
background-attachment:fixed
}
.style3 {
font-family: Tahoma;
font-size: 16px;
}
.style4 {color: #FF0000}
-->
</style>
</head>
<body>
<table width="955" align="center">
<tr>
<td colspan="2"><img src="images/head.jpg" width="955" height="265" /></td>
</tr>
<tr>
<td width="195" height="323" valign="top">
<div align="left">
<table>
<tr>
<td width="187"><a href="ad_permission.php"><img src="images/manu7ad.png" width="187" height="41" border="0" /></a></td>
</tr>
<tr>
<td><a href="ad_profile_employee.php"><img src="images/manu9ad.png" width="187" height="41" border="0" /></a></td>
</tr>
<tr>
<td><a href="ad_data_employee.php"><img src="images/manu8ad.png" width="187" height="41" border="0" /></a></td>
</tr>
<tr>
<td><a href="ad_logout.php"><img src="images/manu5.png" width="187" height="41" border="0" /></a></td>
</tr>
</table>
</div>
<p align="left"> </p> <p align="left"> </p></td>
<td width="756" valign="top"><div align="center" class="style3">
<p> </p>
<p align="center" class="style3">ประวัติการลางาน</p>
<p align="center" class="style3"><?php echo $row_rs_emle['le_name']; ?> <?php echo $row_rs_emle['le_sername']; ?></p>
<form id="form2" name="form1" method="post" action="ad_del_detail.php">
<table width="100%" border="1" align="center">
<tr>
<td width="159"><div align="center">วันที่กรอกข้อมูล</div></td>
<td width="159"><div align="center">ตั้งแต่วันที่</div></td>
<td width="159"><div align="center">ถึงวันที่</div></td>
<td width="119"><div align="center" class="style3">
<div align="center">รายละเอียด</div>
</div></td>
<td width="124"><div align="center">จำนวนวันลา</div></td>
<td width="124"><div align="center">ลบ</div></td>
</tr>
<?php
//ตรวจสอบว่ามีข้อมูล หรือไม่
if ($row_rs_emle != 0) {
$total = 0;
do { ?>
<tr>
<td height="50"><div align="center"><?php echo $row_rs_emle['le_startdate']; ?></div></td>
<td><div align="center"><?php echo $row_rs_emle['le_fulldate1']; ?></div></td>
<td><div align="center"><?php echo $row_rs_emle['le_fulldate2']; ?></div></td>
<td><div align="center"><a href="ad_profile_detailemployee.php?le_id=<?php echo $row_rs_emle['le_id']; ?>"><img src="images/icon/Search-Images-icon.png" width="40" height="40" border="0" /></a></div></td>
<td><div align="center">
<?php
$sum = $row_rs_emle['le_total'];
$total += $sum;
echo $sum;
?>
</div> </td>
<td><div align="center">
<input type="checkbox" name="cbdel[]" id="cbdel" value="<?php echo $row_rs_emle['le_id']; ?>"/>
</div></td>
</tr>
<?php } while ($row_rs_emle = mysql_fetch_assoc($rs_emle)); ?>
<tr>
<td height="23" colspan="4"><div align="right" class="style3">จำนวนวันลาทั้งหมด</div>
<div align="right"></div></td>
<td height="23"><div align="center"><span class="style40 style9"><?php echo $total ?></span></div></td>
<td> </td>
</tr>
<?php
} else { // ถ้าไม่มีที่เลือก?>
<tr>
<td height="4" colspan="6"><div align="center">
<input type="submit" name="cmddel" id="cmddel" value="ลบรายการที่เลือก" />
</div></td>
</tr>
<tr>
<td height="5" colspan="6"><div align="center"><span class="style4">ไม่มีขัอมูลการลางาน</span></div></td>
</tr>
<?php } ?>
</table>
</form>
<p><a href="ad_profile_employee.php">ย้อนกลับ</a></p>
<p> </p>
</div></td>
</tr>
</table>
<p> </p>
</body>
</html>
<?php
mysql_free_result($rs_emle);
mysql_free_result($rs_emle1);
?>
|
|
|
|
|
Date :
2015-11-17 14:36:27 |
By :
jkchilla02 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|