Welcome Guest, Not a member yet? Register   Sign In
Form With Multiple Fields [Array] Query
#2

If you have multiple title/description pairs which you want to loop through and pass as an array to your update_keywords method, you probably need to do something like this:

PHP Code:
// Note: you should probably make sure the $titles and $descriptions contain the
// same number of items, or handle the conditions in which either is larger than
// the other, but we won't do that here for the sake of simplicity.

$titles $this->input->post('keyword_meta_title');
$descriptions $this->input->post('keyword_meta_description');
$max count($titles);
for (
$count 0$count $max$count++) {
    
$data = array(
        
'keyword_meta_title' => $titles[$count],
        
'keyword_meta_description' => $descriptions[$count],
    );
    
$this->website_model->update_keywords($id$data);


As a further optimization, I would normally do the update outside of the loop, but that requires creating an array of entries that can be passed to a batch update method in the model, which requires some more significant changes, including a method in the model to handle a batch update.
Reply


Messages In This Thread
RE: Form With Multiple Fields [Array] Query - by mwhitney - 07-11-2016, 08:55 AM



Theme © iAndrew 2016 - Forum software by © MyBB