Cannot Pass More than two variable to view - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10) +--- Thread: Cannot Pass More than two variable to view (/showthread.php?tid=70523) |
Cannot Pass More than two variable to view - sanjaya - 04-21-2018 Hello, I try to get total of price column in personal assets table. But I have below error.. A PHP Error was encountered Severity: Notice Message: Trying to get property of non-object Filename: employee/inventory.php Line Number: 61 Backtrace: File: C:\wamp64\www\MY\admin\application\views\employee\inventory.php Line: 61 Function: _error_handler File: C:\wamp64\www\MY\admin\application\controllers\Employee.php Line: 223 Function: view File: C:\wamp64\www\MY\admin\index.php Line: 315 Function: require_once My Model: PHP Code: <?php This My Controller PHP Code: function personal_inventory($id) This is my view PHP Code: <!-- Content Wrapper. Contains page content --> RE: Cannot Pass More than two variable to view - Wouter60 - 04-21-2018 This is line 61: PHP Code: <P>Total Spends is <?=$row->price?></P> It gives an error because $row is an array, not an object. So change it into: PHP Code: <p>Total Spends is <?=$row["price"];?></p> RE: Cannot Pass More than two variable to view - sanjaya - 04-21-2018 (04-21-2018, 02:25 PM)Wouter60 Wrote: This is line 61:I have added this code. But it's gave only one product price "Total Spends is 128000" But total spend should be 139909. This correct calculation comes with var_bump like "object(stdClass)#26 (1) { ["SUM(price)"]=> string(6) "139909" }". Have you any idea, Why does not come this correct sum value to the view? But its came to header of the view as var_dump. Looks my screenshot. RE: Cannot Pass More than two variable to view - Wouter60 - 04-21-2018 Okay, I see it now. The $row->price or $row["price"] on line 61 should be the total amount. I think this will do the trick: PHP Code: <p>Total Spends is <?=$total;?></p> You're passing the array $inventory_data to the view. One of the elements in this array is "total", right? Use that to display the total amount. RE: Cannot Pass More than two variable to view - sanjaya - 04-22-2018 (04-21-2018, 11:56 PM)Wouter60 Wrote: Okay, I see it now. The $row->price or $row["price"] on line 61 should be the total amount. Hello Wouter60, Now I got this error. A PHP Error was encountered Severity: 4096 Message: Object of class stdClass could not be converted to string Filename: employee/inventory.php Line Number: 61 Backtrace: File: C:\wamp64\www\MY\admin\application\views\employee\inventory.php Line: 61 Function: _error_handler File: C:\wamp64\www\MY\admin\application\controllers\Employee.php Line: 223 Function: view File: C:\wamp64\www\MY\admin\index.php Line: 315 Function: require_once RE: Cannot Pass More than two variable to view - sanjaya - 04-22-2018 (04-21-2018, 11:56 PM)Wouter60 Wrote: Okay, I see it now. The $row->price or $row["price"] on line 61 should be the total amount. Hello Wouter60, Now I got this error. A PHP Error was encountered Severity: 4096 Message: Object of class stdClass could not be converted to string Filename: employee/inventory.php Line Number: 61 Backtrace: File: C:\wamp64\www\MY\admin\application\views\employee\inventory.php Line: 61 Function: _error_handler File: C:\wamp64\www\MY\admin\application\controllers\Employee.php Line: 223 Function: view File: C:\wamp64\www\MY\admin\index.php Line: 315 Function: require_once RE: Cannot Pass More than two variable to view - Wouter60 - 04-22-2018 Check your model, and change the function employee_spends() : PHP Code: function employee_spends($id) RE: Cannot Pass More than two variable to view - sanjaya - 04-22-2018 (04-22-2018, 10:08 AM)Wouter60 Wrote: Check your model, and change the function employee_spends() : RE: Cannot Pass More than two variable to view - alamowais - 05-21-2018 You have to call it <?=$row->price?> as in array format. RE: Cannot Pass More than two variable to view - InsiteFX - 05-21-2018 PHP Code: // Returns an Object: |