0

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"
     } 
   }
 }
3
  • echo var_dump($data_null); Commented Oct 24, 2017 at 11:12
  • echo in controller method, populate in view Commented Oct 24, 2017 at 11:12
  • Show what code you tried in view Commented Oct 24, 2017 at 11:13

2 Answers 2

1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

;;; Yes, its array inside an array and its was showing null while i send it to the view. Let me try this way as you have mentioned.
0

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;

  }
} 

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.