CodeIgniter Forums
Sum of MySQL rows values and sum of values shouldn't be greater than php variable - 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: Sum of MySQL rows values and sum of values shouldn't be greater than php variable (/showthread.php?tid=77166)



Sum of MySQL rows values and sum of values shouldn't be greater than php variable - olegrain - 07-28-2020

Hello! I use Codeigniter 3.1.11 and have a php variable $maximum_amount with value of '0.50000000'.

In my MySQL database I have a table called 'orders' with a rows for example:

Code:
#table orders
+----------+-----------+--------------+---------------------+
|  OrderID |   UserID  |  amount      |  created_time       |
+----------+-----------+--------------+---------------------+
|   a1bh   |    htl57  |  0.10000000  | 2020-07-27 08:23:11 |
|   2c3f   |    34gh7  |  0.30000000  | 2020-07-27 08:24:49 |
|   4d5s   |    lkr37  |  0.20000000  | 2020-07-27 08:29:03 |
|   5e6k   |    jkw68  |  0.50000000  | 2020-07-27 08:30:04 |
+----------+-----------+--------------+---------------------+

I need to select rows with SUM of 'amount' but the SUM of 'amount' shouldn't be be greater than variable $maximum_amount. I need to use order ASC by 'created_time' and limit '100'. I know what I need to use Cumulative Sum, but I don't know how to do it with Codeigniter. Please, help to solve this.


RE: Sum of MySQL rows values and sum of values shouldn't be greater than php variable - php_rocs - 07-28-2020

@olegrain,

What code do you currently have in place to do a pull from the database? The query that your asking for is not complicated but are you asking for the code as well?