I would like to do a simple sum per salesid in php - mysql after cross calculation between date (2 tables) to get the real time commission, all the value already come out correctly but I have a problem with the final sum per sales id.
Every time there is a change in the input commission form, the new value is inserted:
salesid commission datefrom - dateto aa0001 20% 2010/01/01 - 2010/02/09 aa0001 25% 2010/02/09 - null
and table transac开发者_开发百科tion got
items qty price salesid transactiondate
call value of the table commission where salesid=$_sessionid $today = date in php next week.
if ($dateto == 0) {
$dateto = $today; }
call value of the table transaction where salesid=$_sessionid
I use below range to get the commssion with transaction date:
if ($transactiondate >= $datefrom and $transactiondate < $dateto) {
$subcommission = ($price * $commission) }
and the value come like below:
salesid commission aa0001 1000 bb0001 500 aa0001 200 bb0001 50
I already try with few sample in this web but still cannot meet the correct result. I cannot do the sum in mysql because of some reason (need calculation with other table)
the result will be:
aa0001 1200 bb0001 550
I appreciate any help to complete the test. Thank you so much.
If that's supposed to represent a table with salesid
and commission
columns, you can just do:
SELECT salesid, SUM(commission) FROM table GROUP BY salesid;
Even if it depends on a join you should be able to do it, but lacking details I can't really give an example
You can create an array which key is salesid
and value is commission
and then again filter array for same key. it may help u.
I not too expert with php, because I truely vb programmer. And I not too expert using index, key, or multiple array.
I have solve this problem with using temp table for store temporary data with session. everytime the form open, will be delete data in temp table with session userid and make calculation data and insert to temp table and do the select the data again with sum and group by.
Thank for all of you support and I will learn more from now on.... nice day bro..
精彩评论