 |
|
คือ ของผมอยากจะให้มัน insert ข้อมูล แต่ก่อนจะ insert (insertได้ละครับ) แต่จะเช็ค ว่าในตาราง action มีค่าซ้ำกันหรือไม่ หรือถ้ามีแล้วก้ไม่ต้อง insert แต่ถ้าเช็คว่า .$_POST["status$i"] มีค่าในตารางอยู่แล้ว แต่ไม่ได้เลือก checkbox แล้วให้ทำการลบแทน (งงมะครับ)
ขออนุญาติยืมจากเจ้าของมานะครับ

ประมาณว่า ถ้าปุ่มไหนเลือกแล้ว แต่มีข้อมูลในตาราง(ทุกฟิล)ให้เว้นไว้ ถ้าไม่เลือก checkbox แล้วกดอีกครั้งจะลบข้อมูลในตารางอ่ะครับ
Code (PHP)
mysql_select_db($database_localhost, $localhost);
$query_action = "SELECT member.*,action.* FROM action,member where member.id_m = action.id_member and action.id_member = '".$_POST["id_member$i"]."' and action.id_folder = '".$_POST["id_folder$i"]."' and action.status_action = '".$_POST["status$i"]."' and action.id_a = '".$_POST["status$i"]."'";
$action = mysql_query($query_action, $localhost) or die(mysql_error());
$row_member = mysql_fetch_assoc($action);
$totalRows_action = mysql_num_rows($action);
echo $totalRows_action;
echo $query_action;
for($i=0;$i<=$totalRows_member;$i++)
{
if(($totalRows_action<0)and($_POST["status$i"] != ""))
{
$strSQL = "INSERT INTO action ";
$strSQL .="(id_member,id_folder,status_action,id_a) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["id_member$i"]."','".$_POST["id_folder$i"]."', ";
$strSQL .="'".$_POST["status$i"]."','".$_POST["id_a"]."') ";
mysql_select_db($database_localhost, $localhost);
$Result1 = mysql_query($strSQL, $localhost) or die(mysql_error());
}else if($_POST["status$i"] != 1) {
// ลบ$row_member['id_a']
$strSQL = "DELETE FROM action ";
$strSQL .="WHERE id_a = '".$_POST["id_a"]."' ";
mysql_select_db($database_localhost, $localhost);
$Result1 = mysql_query($deleteSQL, $localhost) or die(mysql_error());
}
}
Tag : PHP, MySQL
|
|
 |
 |
 |
 |
Date :
2013-12-02 21:13:07 |
By :
piz |
View :
1325 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |