Welcome Guest, Not a member yet? Register   Sign In
Controller Issue [Duplicating data to a new entry]
#1

[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.
#2

[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
#3

[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.
#4

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

Works fantastically, thanks a million!

Smile
#5

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




Theme © iAndrew 2016 - Forum software by © MyBB