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] => sachin87@gmail.com
[Password] => 202cb962ac59075b964b07152d234b70
[Conf_password] => 123
[Status] => 0
)
)
)
)
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;
....
要从数据库对象中提取例如阿富汗:
echo $arr[0][0]->country;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.