How do I echo the following result data in the view using foreach loop? When I tried it echoes Null value.
array(13) {
[0]=> array(1) {
[0]=> object(stdClass)#61 (6) {
["ad_no"]=> string(5) "11190" ["name"]=> string(15) "Anjitha S Kumar" ["ctype"]=> string(17) "Kerala University" ["cname"]=> string(9) "BSc Maths" ["net_fees"]=> string(7) "6000.00" ["bal_fees"]=> string(4) "0.00" }
}
[1]=> array(1) {
[0]=> object(stdClass)#60 (6) {
["ad_no"]=> string(5) "10879" ["name"]=> string(7) "Adith P" ["ctype"]=> string(5) "C-DIT" ["cname"]=> string(6) "ADCHNE" ["net_fees"]=> string(8) "11500.00" ["bal_fees"]=> string(4) "0.00" }
}
[2]=> array(1) {
[0]=> object(stdClass)#59 (6) {
["ad_no"]=> string(5) "11785" ["name"]=> string(9) "Akshay AS" ["ctype"]=> string(5) "C-DIT" ["cname"]=> string(6) "ADCHNE" ["net_fees"]=> string(8) "11000.00" ["bal_fees"]=> string(7) "9000.00"
}
}
}
If your variable is named $results you can do (looks you are having array inside array)
View Code:
foreach($results as $result) {
foreach($result as $innerresult) {
echo $innerresult->ad_no;
}
}
Just make sure you are passing the variable from the controller to your view.
Controller code:
$data['results'] = $results;
$this->load->view('viewname',$data);
From your var_dump()
result.the data contains array and array contains array of objects.You should try something like this.
foreach($data_array as $object_array) {
foreach($object_array as $object){
echo $object->ad_no;
echo $object->name;
}
}