sheriff Posted May 31, 2007 Share Posted May 31, 2007 hi all ... I have a list generated from mysql with products what have not delivered to customers. how can i tell to php or mysql ??? to cumulate the items with the same id and to calculate the quantity of the items ? exemple: Nr. ID The product UM QTY ord nr 1 88 Antene pentru plase volei per 2 767762 2 88 Antene pentru plase volei per 1 791688 3 305 Aparat de măsurat detenţa buc 1 264954 4 305 Aparat de măsurat detenţa buc 2 659272 5 286 Aparat de ramat HAMMER buc 2 767762 6 286 Aparat de ramat HAMMER buc 1 419495 7 286 Aparat de ramat HAMMER buc 1 430298 8 286 Aparat de ramat HAMMER buc 1 219941 9 286 Aparat de ramat HAMMER buc 7 825287 10 286 Aparat de ramat HAMMER buc 1 791688 and i want to show something like: 1 88 Antene pentru plase volei per 3 767762 2 305 Aparat de măsurat detenţa buc 3 264954 35 286 Aparat de ramat HAMMER buc 13 767762 the code what i use now: $query = "select prod_com.pr_id, prod_com.ord_nr, prod_com.cmd_id, prod_com.pr_qty, products.pr_name, products.pr_desc, products.pr_um, products.pr_price from prod_com, products WHERE prod_com.pr_id=products.pr_id and prod_com.pr_id=prod_com.pr_id and prod_com.pr_date_deliv is NULL ORDER BY products.pr_name"; thanks! Quote Link to comment https://forums.phpfreaks.com/topic/53708-solved-report-products-or-cumulate-same-rows/ Share on other sites More sharing options...
sheriff Posted May 31, 2007 Author Share Posted May 31, 2007 The solution is: $query = "SELECT prod_com.pr_id, prod_com.ord_nr, prod_com.cmd_id, prod_com.pr_qty, sum(prod_com.pr_qty) AS total_quantity FROM prod_com GROUP BY prod_com.pr_id"; the reference: http://www.thescripts.com/forum/thread647763.html Very cool thing ! Quote Link to comment https://forums.phpfreaks.com/topic/53708-solved-report-products-or-cumulate-same-rows/#findComment-265482 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.