I think this is probably a simple one, but I am just trying to think of the most effective way of doing what I want.
What I have, is a page that allows a manager, to edit user’s within their own department.
This works fine at its most basic, where by I run a query to return all users WHERE Department=managers department.
This will return all users within the same department. What I would like to do, is expand upon that, as some managers are responsible for several departments, and want to be able to edit users from various departments.
My thinking was to have a department table, with an entry for the user. There would then be a column for each department, and I would set the value to Yes for each department the manager is responsible for.
The tricky part would then be to adjust the query based on that information. What do you all think would be the best way to query the row, and for each field with a value of Yes, add on the department as an option in the query
I could do:
$row = mysql_fetch_assoc($result);
If($row['dept1'] == 'Yes') {
$query. = " OR Department=dept1";
}
if($row['dept2'] == 'Yes') {
$query. = " OR Department=dept2";
}
This would work I imagine, but would mean that I would need to manually go in and hard code a department if we were to add one or remove one etc.
Is there a more elegant solution?
I don’t think there can be a better solution, but a cleaner one is the following:
and you make an array of departments you want to include, and then implode() the array into “IN ()” phrase of the query, like this: