0

I am using a CodeIgniter. i am getting value in array in controller but not getting in view. I am using this controller to get countries from database and on view page i want to show these countries in pagination.

CONTROLLER

public function admin($Username = NULL, $arr = NULL){

            if($this->session->userdata('is_log_in')){
                    $this->load->model('User');
                    $Username = $this->session->userdata('Username');
                    $form_data['results'] = $this->User->view_table($Username);
                    $arr = array();
                    $arr[]= $this->countries();
                    $arr[] = $form_data;
                    echo "<pre>";
                    print_r($arr);  // getting all value here
                    $this->load->view('templates/header');
                    $this->load->view('User/User_admin', $arr);                  
                    $this->load->view('templates/footer');
               }else{
                    $form_data['msg'] = "Your Can't access this account";
                    $this->index($form_data);         
            }           
        }

VIEW

if(isset($arr)){
 if ($arr->num_rows() > 0){
          print_r($arr); 
}};

updated

Above problem is solved.

now updated question is how to extract these array stdClass Object

Array
(
    [0] => Array
        (
            [0] => stdClass Object
                (
                    [ccode] => AF
                    [country] => Afghanistan
                )

            [1] => stdClass Object
                (
                    [ccode] => AX
                    [country] => Ã…land Islands
                )

            [2] => stdClass Object
                (
                    [ccode] => AL
                    [country] => Albania
                )
       )

    [1] => Array
        (
            [results] => Array
                (
                    [0] => stdClass Object
                        (
                            [id] => 7
                            [Username] => sachin
                            [First_name] => shagun
                            [Last_name] => sood
                            [Email] => [email protected]
                            [Password] => 202cb962ac59075b964b07152d234b70
                            [Conf_password] => 123
                            [Status] => 0
                        )

                )

        )

)
2
  • 1
    Change $arr[] to $arr['arr'][] then print_r($arr) in your view to see its format Commented Jun 18, 2013 at 13:29
  • Are you print array in User/User_admin view ? Also check without any if statement in view. Commented Jun 18, 2013 at 13:34

2 Answers 2

1

Change

$this->load->view('User/User_admin', $arr);

to

$data['arr'] = $arr;
$this->load->view('User/User_admin', $data);

Then $arr will work in the View file.

For your second (updated) question:

foreach ($arr[0] as $a)
{
    echo $a->ccode;
    echo $a->country;
}

And

echo $arr[1]['results'][0]->id;
echo $arr[1]['results'][0]->Username;
....    
Sign up to request clarification or add additional context in comments.

Comments

0

To extract for instance Afghanistan from your database object:

echo $arr[0][0]->country;

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.