• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A PHP Error was encountered Severity: Notice Message: Undefined variable: company_n

#1
controller code:

Code:
$vendor=$this->vendormodel->vendor_details($login_email);
$this->load->view('vendor_dashboard',$vendor);



view code:
Code:
<div class="form-group">
                           <label>Company Name</label>
                           <input type="text" class="form-control" name="company_name" value="<?php echo  $company_name; ?>" required>
                       </div>

error::
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: company_name
Filename: views/vendor_dashboard.php

print_r($vendor); results to::
Array ( [0] => stdClass Object (  [company_name] => P.A  ) )


plz help
Reply

#2
controller
PHP Code:
$vendor=$this->vendormodel->vendor_details($login_email);
$this->load->view('vendor_dashboard', array('vendor' => $vendor)); 

view
PHP Code:
<?php echo $vendor->company_name ?>
Reply

#3
I'd suggest using row() at the end of your model query instead of result_array() because it's not returning a single object, it's returning an array of objects. 

so, you've two options...

1:
in your model: 

PHP Code:
$query $this->db->where('email'$login_email)->get('mytable')->limit(1)->row();
return 
$query



PHP Code:
// Controller

$vendor $this->vendormodel->vendor_details($login_email);

print_r($vendor);
// returned to your controller
//
// stdClass Object (  
// [company_name] => P.A
// [user_name] = SomeUser
// [IP_Address] = 127.0.0.1
// ...
//  )

$this->load->view('vendor_dashboard',$vendor); 


It's then converted to $company_name, $user_name, $IP_Address, etc in your view.


-----
Option 2 (while this will work, it's ugly and will cause confusion later)

Pass $vendor[0] in your view call.

PHP Code:
$this->load->view('vendor_dashboard',$vendor[0]); 

then access as $company_name, $user_name, etc in your view...
Reply

#4
(07-03-2016, 07:32 PM)pdthinh Wrote: controller
PHP Code:
$vendor=$this->vendormodel->vendor_details($login_email);
$this->load->view('vendor_dashboard', array('vendor' => $vendor)); 

view
PHP Code:
<?php echo $vendor->company_name ?>

Not quite...

PHP Code:
// view file

<?php echo $vendor[0]->company_name ?>
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.