@jmyrtle Apologies for overwhelming you. I tossed a bunch of new stuff at you. Slow day for me.
Recall that the original problem with your code was that it was not taking into account the fact that select elements are not actually posted for disabled elements resulting in null values in your database. You seemed to be having difficulty understanding and correcting this. Which is fine. You have a pretty big file and it can be hard to isolate things.
So what I first did was to try and demonstrate the problem with a simple test file. That was my first 24 line bit of code. As you surmised, all that var_dump does is to show the value of a variable. It’s a quick and easy way to see that $_POST did not contain a value for status. I then showed one way to to ensure it always will have a value using a hidden element.
You can go back to your original code, fix this issue and that particular problem should be resolved. And then move on. Probably your best choice.
But we did have some further discussion which led me to post 82 line second example. The idea was to show a more ‘organized’ approach to building pages. I suspect it failed miserably.
Going back to the big picture, one fundamental concept that applies across most programming is to try and isolate the view (i.e. html rendering) from the rest of your code. The view should not care about where the data it needs is coming from and should be separated as much as possible from the rest of your code. In my case, the render method represents the view.
The view needs to know the current user’s id. It does not need to know that it comes from a session or maybe some place else. Hence, in my test code, I just set the value and passed it to render. In your code you would pull it from the session. The point is that the view does not care. It just needs the value.
Likewise the view does not care where $rowUser comes from. I certainly did not want to setup a complete database and query from it. So I just faked one. In your code, you would actually pass the $rowData from your query. The view won’t care.
Again, this is all just about separating your view from the rest of your code. render($currentUserId,$rowUser) tells us exactly what your view needs.
As far as the multiple render methods, another key approach to programming is to try and break things down into smaller chunks of code so you can see what is going on.
html - render
body
form - renderContent
select status - renderStatus
The render method main job is generate the html page skeleton. Basically the html header section. It’s the sort of thing that will get repeated for pages so you kind of want to isolate it. Eventually you would want to share this code across multiple pages.
The renderContent generates html for a given page. In this case it is just a form. Many form elements such as inputs and buttons are fairly simple so we can just render them directly.
However, the status element needs a bit more work. So in keeping with the divide and conquer approach, we give it it’s own renderStatus ($currentUserId,$userId,$status) method. Notice that $rowUser is not passed. Instead, we pass it the exact variables that it needs to do it’s job. It’s a subtle point but it can makes it easier to understand exactly what the method is doing.
I was not comfortable with the actual renderStatus code I posted because it basically renders the same thing three time based on some conditions. It’s not going to work well if you have more than two options or make other changes. I was trying to follow your coding style and not add yet another new concept. I could post an updated more generic method but again that would be even more new code and concepts.
In conclusion, fix your original code and move on if you like.