mysql - How to push new index and value to php array? -
i fetching data table using group payment method. happen in group data comes corresponding data in table . want payment types shown in result . using following query.
 $query = "select  paytype ,sum(totalamount)  `tbl_payments` group paytype";   there 5(cash,credit,paypal..) types of payment . want payment methods result , if paytype not find query result should appended ['credit'] =>[0] , means paytype => amount(which should 0 @ case).
please me on this.
you didn't tell table paytype containing list of valid payment methods. 
to payment methods in result, must use left join. :
select pt.paytype, sum(p.totalamount) `tbl_paytypes` pt left join `tbl_payments` p  on pt.paytype = p.paytype  group pt.paytype      
Comments
Post a Comment