retrieving and showing data - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: retrieving and showing data (/showthread.php?tid=65690) Pages:
1
2
|
retrieving and showing data - davy_yg - 07-12-2016 Hello, I am trying to show data in here but have not been successful yet. controllers/cpages.php PHP Code: public function pcategories() { views/pcategories.php PHP Code: <div class="widget-box"> The Result: A PHP Error was encountered Severity: Notice Message: Array to string conversion Filename: views/pcategories.php Line Number: 54 Backtrace: File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\views\pcategories.php Line: 54 Function: _error_handler File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\controllers\Cpages.php Line: 46 Function: view File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\index.php Line: 315 Function: require_once Array Womens A PHP Error was encountered Severity: Notice Message: Array to string conversion Filename: views/pcategories.php Line Number: 60 Backtrace: File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\views\pcategories.php Line: 60 Function: _error_handler File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\controllers\Cpages.php Line: 46 Function: view File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\index.php Line: 315 Function: require_once SQL DATABASE - TABLE: menu_parent ctgparent_name ctgp_no ctgparent_description Men 0 Description How to fix the error so that I can see the result? RE: retrieving and showing data - arma7x - 07-12-2016 The message 'Array to string conversion' mean you echoing array datatype without looping it to retrieve each subvalue. RE: retrieving and showing data - davy_yg - 07-12-2016 I try this: views/pcategories.php PHP Code: <table border="0" style="width: 100%; height: 90px;"> Controllers/cpages.php PHP Code: public function pcategories() { Still get this error message: A PHP Error was encountered Severity: Notice Message: Undefined variable: data Filename: views/pcategories.php Line Number: 54 Backtrace: File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\views\pcategories.php Line: 54 Function: _error_handler File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\controllers\Cpages.php Line: 46 Function: view File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\index.php Line: 315 Function: require_once Womens A PHP Error was encountered Severity: Notice Message: Undefined variable: data Filename: views/pcategories.php Line Number: 60 Backtrace: File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\views\pcategories.php Line: 60 Function: _error_handler File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\controllers\Cpages.php Line: 46 Function: view File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\index.php Line: 315 Function: require_once How to fix the error messages? \ RE: retrieving and showing data - arma7x - 07-12-2016 Didn't see any $data['posts'] in your controller. When passing $data to view(), the view file will have $posts as variable. RE: retrieving and showing data - mwhitney - 07-12-2016 Your controller defines $data['ctgparent_name'] and $data['ctgparent_description'], then passes $data to the view. So, in the view, you would access this data as $ctgparent_name and $ctgparent_description. As arma7x mentioned, you didn't show any code which defines $posts in the view or $data['posts'] in the controller, though I'd have to assume that it's defined somewhere, since you're not getting an error on the foreach() loop (unless you're calling $data somewhere before the view code you've included here). RE: retrieving and showing data - rtenny - 07-12-2016 (07-12-2016, 07:34 AM)davy_yg Wrote: Hello, I think your function $this->Mpages->retrieve_parentctg(); is return an array rather then a plain string. RE: retrieving and showing data - InsiteFX - 07-12-2016 He's open <TR> tags but he is never closing any of them. RE: retrieving and showing data - davy_yg - 07-12-2016 (07-12-2016, 09:18 AM)rtenny Wrote:(07-12-2016, 07:34 AM)davy_yg Wrote: Hello, How to make it works? models/Mpages.php PHP Code: public function retrieve_parentctg() RE: retrieving and showing data - InsiteFX - 07-13-2016 What is Mpages returning a result(),result_array(),row() or row_array() If it doe's not end with an array then you are returning an object not an array. RE: retrieving and showing data - rtenny - 07-13-2016 (07-12-2016, 09:30 PM)davy_yg Wrote:(07-12-2016, 09:18 AM)rtenny Wrote:(07-12-2016, 07:34 AM)davy_yg Wrote: Hello, to find out what is actually returned add this just before the call of the view print_r($data['ctgparent_name']); die; |