A User clicks on ‘View Users’ and the php logic fetches the data using MySQL SELECT, passes the data to the table_view, then displays all the ‘Users’ on the system.
Each table row has a ‘edit’ hyperlink which fetches an array or form elements, this array of form elements is passed to a ‘Form_Generator’ which generates the html for the form array, the values for the form are also added in.
So the User is faced with a form ( sometimes 20 elements large ) with the form element values matching the values in the database.
MY QUESTION IS…
How can I make the update dynamic? If not dynamic, how can I make it better?
My current Method is so…
When the user has eddited the values they submit the form, then validation.
might i add that one form may consist of 3 or more tables in the relational database
I could write an update statement for EACH element like:
if ( isset ( $user_input["firstname"] ) )
{
$this -> _database -> update( "UPDATE users SET firstname = '{$user_input["firstname"]}' WHERE user_id = $user_id" );
$this -> _database -> execute();
}
etc etc for ALL fields
or I could use an UPDATE statement with JOINS to update multiple fields at once. like so:
$this-> _database -> custom("UPDATE fitters AS f INNER JOIN user_types AS ut ON f.fitter_id = ut.type_id INNER JOIN users AS u ON u.user_id = ut.user_id SET f.title = '{$user_input["title"]}', f.firstname = '{$user_input["firstname"]}', f.surname = '{$user_input["surname"]}', u.email_address = '{$user_input["email_address"]}' WHERE u.user_id = {$user_input["user_id"]}");
Does anybody know of a better way to do this?
How have you tackled updating database information in your projects?
Using a framework for applications makes life alot easier. I personally like to work with CodeIgniter.
When using a framework like CodeIgniter database operations become a lot easier. Here is an example of how it could be:
http://codeigniter.com/
This is great website with tutorials to get you started on the subject!
http://heybigname.com/2009/09/04/developing-a-website-with-code-igniter-part-1-configuration/