CodeIgniter Forums
Controller Issue [Duplicating data to a new entry] - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Controller Issue [Duplicating data to a new entry] (/showthread.php?tid=53337)



Controller Issue [Duplicating data to a new entry] - El Forum - 07-19-2012

[eluser]DannGrant[/eluser]
Hi guys,

I may just be being really stupid here but any help would be greatly appreciated.

I have a method to recreate a 'ticket' with a new ticket number and all of the same information that comes with it. Along with each ticket are accompanying notes which come from a separate database table. I need to re-enter those notes with the new ticket number i've provided.

Code:
public function recreate_ticket()
{
  $this->data['notes'] = $this->note->order_by('created', 'desc')->get_many_by('ticket_id', $this->uri->segment(4));
  
  if($this->ticket->insert(array(
   'no'  =>  $this->input->post('ticket_no'),
   'subject' =>  $this->input->post('subject'),
   'issue'  =>  $this->input->post('issue'),
   'user_id' =>  $this->input->post('user_id')
  )))
  {
   foreach($notes as $n) {
    $note = array(
     'ticket_id'  =>  $this->uri->segment(4),
     'user_id'  =>  $n->user_id,
     'note'   =>  $n->note,
     'created'  =>  $n->created
    );
    
    $this->note->insert($note);
    redirect('admin/tickets');
   }
  }
}

The error i'm receiving is that my foreach statement is using an undefined variable which i'm guessing is because i'm trying to use the data in the same method i'm pulling it. Is there any way around this?

Thanks in advance.


Controller Issue [Duplicating data to a new entry] - El Forum - 07-19-2012

[eluser]CroNiX[/eluser]
You are foreach()ing over $notes. I don't see a defined $notes in that function. I see a $this->data['notes'], though Smile


Controller Issue [Duplicating data to a new entry] - El Forum - 07-19-2012

[eluser]CroNiX[/eluser]
Another thing is you have a redirect within a loop. That will trigger only once and exit the loop since it's redirecting back to tickets.


Controller Issue [Duplicating data to a new entry] - El Forum - 07-19-2012

[eluser]DannGrant[/eluser]
I love you a lot right now.

Works fantastically, thanks a million!

Smile


Controller Issue [Duplicating data to a new entry] - El Forum - 07-22-2012

[eluser]Developer13[/eluser]
[Author Removed Post]