how to write this sql with active record |
Hello everyone, I'm trying to calculate profit from two tables province_income and province_expenses. But I'm getting difficult to organize sql statement with ci4 query methods to make it work.
Help please, Thanks. here is my sql PHP Code: SELECT Date, SUM(Income) as Income, SUM(Expense) as Expense, SUM(Income) - SUM(Expense) as Profit
@venance,
Have you thought about using query binding (https://codeigniter.com/user_guide/datab...y-bindings) instead? This way you can put the query in as you have it above. (03-18-2021, 08:09 AM)php_rocs Wrote: @venance,Yes I have used it, but because I want to use paginate(), the query() didn't work. All I want to get data and use pager PHP Code: $this->table("mytable")->paginate(5); PHP Code: $sql = "mystatement";
@venance,
Have you considered using something like Datatables (https://datatables.net/)? Then you don't have to worry about pageination. Or you could create a variable that holds the range of records and whenever the query is run it only pulls the next set of records based on the variables value. (03-18-2021, 11:35 AM)php_rocs Wrote: @venance,Thank you, I think for this issue a datatable would be the best solution |
Welcome Guest, Not a member yet? Register Sign In |