Jump to content

Checkbox Updating


kmark

Recommended Posts

Hi,

 

I have a page in my application where managers are assigned employees.  Currently you click on the managers name and that takes you to a page where all the employees are listed with a checkbox beside their name.  If the checkbox is checked then that employee is assigned to that manager using the code below (MSSQL database).

 

if(count($_POST['link'])) {
	$sql = "INSERT INTO tblAssignment (employeeID1, employeeeID2) (SELECT $id, ". implode (') UNION (SELECT '. $id .', ',  $_POST['link']) .")";
}

 

That is working fine

 

What i just realized now is that employees can be unassigned-unchecked (deleted from the assignment table) and I don't want to have duplicate entries either. What would be the best way to filter the checkboxes to make sure that if a box has been unchecked that the row gets deleted or if it stays checked that it does not get entered again?

Link to comment
https://forums.phpfreaks.com/topic/109950-checkbox-updating/
Share on other sites

hmmmm, i guess what i'm trying to avoid is having to loop through all the employees and check if they are assigned or not and the run a query for each employee.

 

So what im thinking is would it be better if when the form is submitted all the assignments to that manager are deleted and the just run the one Insert query i have above?

 

I think this makes sense but let me know what you think.

Link to comment
https://forums.phpfreaks.com/topic/109950-checkbox-updating/#findComment-564766
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.