Forum Moderators: open
What I am trying to do is remove rows matching on selected users and particular task assignments. The only way to avoid deleting the wrong rows is to delete a row only if the information matches on all three columns.
I've got it working ~sometimes~ in a very buggy way with the code below. I'm hoping someone might be able to tell me how I can make it work reliably.
CODE:
$sql="SELECT * FROM $TASK_ASSIGNMENTS_TABLE";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<form name="frm" method="post" action="">
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr><INPUT TYPE="hidden" name="PROJECT_ID[]" value="<? echo $rows['PROJECT_ID'];?>"><INPUT TYPE="hidden" name="TASK_ID[]" value="<? echo $rows['TASK_ID'];?>">
<td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['username'];?>"></td>
</tr>
<?php
}
?>
<tr><td><input name="delete" type="submit" value="DELETE"></form></td></tr></table>
<?
if(isset ($_POST['delete'])){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM $TASK_ASSIGNMENTS_TABLE WHERE TASK_ID='$TASK_ID[$i]' AND username='$del_id' AND PROJECT_ID='$PROJECT_ID[$i]'";
$result = mysql_query($sql);
}
I can get it to remove all rows for a particular user if I just match on the username but, trying to match on the above is a real problem.