1

A PHP Error was encountered Severity: Notice

Message: Undefined variable: result

Filename: user/messages.php

Line Number: 87

Backtrace:

File: E:\xampp\htdocs\ci\application\views\user\messages.php Line: 87 Function: _error_handler

File: E:\xampp\htdocs\ci\application\controllers\users\Dashboard.php Line: 12 Function: view

File: E:\xampp\htdocs\ci\index.php Line: 315 Function: require_once

here is my code Controller

      <?php defined('BASEPATH') OR exit('No direct script access allowed');
        class Bills extends CI_Controller{
       function __construct(){
      parent::__construct();
     }

     public function bill(){
     $id = $this->session->userdata('email');
     $this->load->database();
     $this->load->helper(array('form', 'url', 'html'));
     $this->load->model('fuser/Bill');
     $data['result'] = $this->Bill->bills();
     $this->load->view('user/messages',$data);
      }
      }
      ?>

**Model**

      <?php  
     class Bill extends CI_Model  
     {  
      function __construct()  
      {  
         // Call the Model constructor  
         parent::__construct();  
      }  
      //we will use the select function  
      public function bills($id)  
      {  
         //data is retrive from this query  

     $query = $this->db->get('invoices'); 
       return $query->result();   
      }  





      }  
     ?> 

**View**
      <div class="billing_tabs_text_part">
                <?php foreach($result as $row){?>
                  <p><?php echo $row['book_id']; }?></p>
                </div>
Masivuye Cokile
  • 4,754
  • 3
  • 19
  • 34
vikas choudhary
  • 41
  • 1
  • 1
  • 7

5 Answers5

2

i am not sure which section is your problem so i suggest something how to find error

public function bill()
{
    echo 'ok'; // check controller work
    $id = $this->session->userdata('email');
    $this->load->database();
    echo 'ok1';
    $this->load->helper(array('form', 'url', 'html'));
    echo 'ok2';
    /*$this->load->model('fuser/Bill');
    $data['result'] = $this->Bill->bills();
    $this->load->view('user/messages', $data);*/
}

if this is print ok, ok1 , ok2 then this is query problem , if no print ok,ok1 then this is not query problem

in this case try to find error, if other ok then must print ok

public function bill()
{
    echo 'ok';
    /*$id = $this->session->userdata('email');
    $this->load->database();
    $this->load->helper(array('form', 'url', 'html'));
    $this->load->model('fuser/Bill');
    $data['result'] = $this->Bill->bills();
    $this->load->view('user/messages', $data);*/
}
Shafiqul Islam
  • 5,570
  • 2
  • 34
  • 43
0

use <?php echo $row->book_id; }?> in view

because your data is object array.

Praveen P K
  • 198
  • 12
0

You need to find where the problem is exactly

try to var_dump the results and see if you're actually getting any results and that result is not a null or false;

so before this line: $data['result'] = $this->Bill->bills();

try to

var_dump($this->Bill->bills());     
die();

if you're getting results try the other way using dummy content instead of $this->Bill->bills(); use :

$data['result'] = [0 => 1, 1 =>2]; and var_dump from the view

see if you're getting results, and in line where you have

  return $query->result();   

make it like this:

  return $query->result() ? : [];
Emad Ha
  • 1,203
  • 15
  • 33
  • i am not getting any result after do that – vikas choudhary Jun 08 '17 at 12:00
  • if you're not getting results after ? : [] ; and without any php warning then most probably it's because the query is not returning any results in the first place, you need to debug the $db->get('invoices'); part, see if you have data there and look if the db->get is working as it should, you should be almost near the solution :) – Emad Ha Jun 08 '17 at 12:18
  • return $query->result() ? : []; this means, that if $query->result() is `null` or `false` it will return an empty array instead, assuming the result should always be `array` and not false or null – Emad Ha Jun 08 '17 at 12:33
0

What gives you $query->result(); try to print in model itself

0

don't return , print and check the result ex: var_dump($query->result());