Go easy (still learning).
Just wondering what the best approach would be for dynamically updating a record in mysql using PHP without using a loop when defining the row data as an array (key=column name, value=value).
I'd like to prepare the key and value from the array as a string and run the query once instead of iterating through the array using a loop for each key/value.
e.g.
I can figure out how to do it using a foreach loop; and I can easily prepare a variable when inserting multiple records using php implode function. I just can't figure out what the best approach would be for updating the table in the same fashion.
Just wondering what the best approach would be for dynamically updating a record in mysql using PHP without using a loop when defining the row data as an array (key=column name, value=value).
I'd like to prepare the key and value from the array as a string and run the query once instead of iterating through the array using a loop for each key/value.
e.g.
PHP Code:
$data = array('col1' => 'one',
'col2' => 'two',
'col3' => 'three'
);
$str = ????
$query = ("UPDATE table_name SET ".$str." WHERE some_column=some_value")
I can figure out how to do it using a foreach loop; and I can easily prepare a variable when inserting multiple records using php implode function. I just can't figure out what the best approach would be for updating the table in the same fashion.