0
$this->layout='defaultall';

    $id = $this->Auth->user('idUser');
    $data= $this->Contact->find('all',array(
        'conditions' => array('Contact.User_id' => $id)));
          $this->set('contacts',$data);


 $this->loadModel('Calllog');

  /*  for($i=1; $i < 2; $i++)
    {
        $mobile =$data[$i]['Contact']["mobileNo"];
        $work =$data[$i]['Contact']["workNo"];
        $home =$data[$i]['Contact']["homeNo"];*/



   for($data as $datas){

      $mobile=  $datas['Contact']['mobileNo'];
      $home=  $datas['Contact']['homeNo'];
      $work=  $datas['Contact']['workNo'];




      $recent=$this->Calllog->find('all',
          array('order'=>'Calllog.idCallLog DESC',
              'limit' => 1,
              'conditions' => array('Calllog.mobileNo' => array($mobile,$work,$home ),
                  'Calllog.User_id' => $id


              )));

      //here array want to declare


      $this->set('a',$recent);

//here i want to declare an another array which saves the data of every iteration..because i dont want override the data

sorry i am week in arrays.. and do tell me how can i then print the array ...if i want to display the 1st iteration result in my view page

4
  • use '$this->{Model}->create()' Commented Jun 19, 2013 at 8:15
  • do you want to save data of each iteration to $recent array in the same level or each iteration should be in separated arrays in $recent array? Commented Jun 19, 2013 at 9:03
  • i want to save each iteration of recent in seperate array .. so then in my view page if i want to show the result of first iteration i can display it Commented Jun 19, 2013 at 9:17
  • make $recent to $recent[]. This will have all the records of the loop. later you can iterate this loop in the view Commented Jun 19, 2013 at 12:05

1 Answer 1

1

If you just want to add new element to the array without deleting its content you can do that just like that:

$recent[] = 'new_string1';

or if you have more elements:

array_push($recent, 'new_string1', 'new_string2');

But in the future, please read manual: http://php.net/manual/en/function.array-push.php

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.