php - Use query results to insert into second table - Codeigniter -


i creating application using code igniter , having trouble inserting rows table based on results query.

what want select set of tasks based on job , insert tasks table records if has been completed or not e.g.

table tasks taskid taskgroup taskdesc 1      washcar    bucket 2      washcar    fill water 3      washcar    add soap 4      polishcar  buffer 5      polishcar  polish 6      polishcar  power lead 

so user fill in form , select type of job going go e.g. wash car or polish car , want list of task id's relate wash car , insert them work table records if task has been done or not e.g.

work table workid taskid taskdate taskcomplete 1      1      01/01/2015 n 2      2      01/01/2015 n 3      3      01/01/2015 n 

at moment when submit form other tables populated work table not being populated - no errors doesnt populated.

this have in model (that have pieced other stack overflow questions):

$workduedate = date('y-m-d h:i:s', strtotime('14 days')); $creator4 = $this->session->userdata('logged_in'); $wkcreator = $creator4['id'];  $workcreator = $wkcreator; $workcreatedate = date('y-m-d h:i:s'); $this -> db -> select('taskid'); $this -> db -> from('task'); $this -> db -> ('taskgroup','washcar'); $this -> db -> order_by('taskid', 'asc'); $workquery = $this -> db -> get(); return $workquery->result_array(); for($i=0; $i<$workquery;$i++){ $insertwork = array(                     'taskid' => $workquery[$i],                     'taskdate' => $workduedate,                     'taskcomplete' => 'n',                     );    $this->db->insert('work_w',$insertwork);         } 

as can see new , having problems getting work. latest iteration, have tried foreach loops , cant seem work.

does have thoughts on doing wrong here or how best acheieve this?

thanks

edit

updated code:

$workduedate = date('y-m-d h:i:s', strtotime('14 days')); $creator4 = $this->session->userdata('logged_in'); $wkcreator = $creator4['id'];  $workcreator = $wkcreator; $workcreatedate = date('y-m-d h:i:s'); $this -> db -> select('taskid'); $this -> db -> from('task'); $this -> db -> ('taskgroup','washcar'); $this -> db -> order_by('taskid', 'asc'); $workquery = $this -> db -> get(); foreach ($workquery $wtid){         $insertwork = array(                 'taskid' => $wtid['taskid'],                 'taskdate' => $workduedate,                 'taskcomplete' => 'n',                 );         $this->db->insert('work_w',$insertwork);   } 

as other users mentioned, have return right before loop.

but not right way task. first of all data-related better in stored procedure in database instead of php. second, possible achieve same result without using loop @ all:

insert work_w (taskid, taskdate, taskcomplete) select task_id, date_add(current_date, interval 14 day), 'n' task taskgroup = 'washcar' order taskid 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -