(04-21-2018, 02:25 PM)Wouter60 Wrote: 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>
like the way you've done in line 38 to 43.
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.
(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.
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.
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
(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.
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.
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
Check your model, and change the function employee_spends() :
PHP Code:
function employee_spends($id) { $query = $this->db->query("SELECT SUM(price) as total FROM inventory WHERE employee_id=" . $id); if ($query->num_rows() == 0) { return 0; } else { return $query->row()->total; } }
(04-22-2018, 10:08 AM)Wouter60 Wrote: Check your model, and change the function employee_spends() :
PHP Code:
function employee_spends($id) { $query = $this->db->query("SELECT SUM(price) as total FROM inventory WHERE employee_id=" . $id); if ($query->num_rows() == 0) { return 0; } else { return $query->row()->total; } }