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

To do the update as a batch, you would do something like this:

PHP Code:
$data = array();

for (
$count 0$count $max$count++) {
    
$data[] = array(
        
'id' => $id[$count],
        
'keyword_meta_title' => $keyword_meta_title[$count],
        
'keyword_meta_description' => $keyword_meta_description[$count],
        
'keyword_meta_keywords' => $keyword_meta_keywords[$count],
        
'keyword_slug' => $keyword_slug[$count],
        
'keyword_heading' => $keyword_heading[$count],
        
'keyword_content' => $keyword_content[$count]
    );
}

$this->website_model->batch_update_keywords($data); 

This assumes that $id is an array of ID values which can be used to identify the data to be updated in the batch update. Essentially, as you indicated, this would be a hidden field using an array for the name just like the other fields in the form.

As you can see, $data is defined as an empty array before the for loop starts, then each iteration of the loop appends an array to $data (rather than redefining $data), so you have a 2-dimensional array, similar to the output of result_array() when you're working with a database query. Then the batch_update_keywords() method in the model just has to perform a batch update, which is relatively easy using query builder's update_batch() method (especially since we've just created $data in the format required by this method). Query builder's update_batch() just needs the table name, $data, and the name of the key ('id' in the example above).
Reply


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



Theme © iAndrew 2016 - Forum software by © MyBB