I have a table of users. Each user has an enabled flag that is either 1 or 0.
Say I want to have a select box with all enabled users, that’s easy enough to do. My trouble comes down the road when a user is editing a form and it pulls up the currently enabled users, but the currently selected user is not an enabled user.
Normally my query would be something like
SELECT first_name, last_name from users WHERE enabled = 1
However, if this is an edit form, and the currently selected user isn’t enabled anymore and the user submits the form, I will lose the currently selected user.
What would be the best way to handle this? The only way I can think to do it is to create a join in the query that also gets the currently enabled user but I’m wondering if there is a better way. Mainly because some of our forms have this user field in 5 or 6 places on a page and I would have to have to make 5 or 6 different queries just so that I could get the current user.
I think I finally understand the problem. The easiest way I could approach this is by loading ALL users but only filter them when you’re building the drop-down.
The drop-down condition would become something like:
You can do the same thing with a
JOINcondition in SQL, but that would require more work if multiple roles are present on the form.Whether or not loading ALL users is a problem, I can’t tell 🙂