Codeigniter array issue -


i'm trying loop through array , insert values database. table looks this:

  • hours_day
  • hours_open
  • hours_close

my form enables user select day, opening time , closing time. there plus button adds day below it, user can choose whichever days wish. means select box names arrays, i.e. hours_day[]

my model looks this:

$hours = array(     'hours_day' => $this->input->post('venue_hours_day'),     'hours_opening' => $this->input->post('venue_hours_open'),     'hours_closing' => $this->input->post('venue_hours_close'), ); 

so have array ($hours) arrays inside of (hours_day, hours_opening, hours_closing). how loop through add database?

you can use :

$post_day = $this->input->post('venue_hours_day'); $post_opening = $this->input->post('venue_hours_open'); $post_closing = $this->input->post('venue_hours_closing');  $count = count($post_day); $results = array();  ($i = 0; $i < $count; $i++) {     $results []= array(       'hours_day' => $post_day[$i],       'hours_opening' => $post_opening[$i],       'hours_closing' => $post_closing[$i]     ); }  $this->db->insert_batch('your_table', $results); 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -