Home » questions » how to count no.of room of room type? help me plz...?

how to count no.of room of room type? help me plz...?

2006-08-08 18:23:43, Category: Programming & Design
room type is stored in field in string format eg: standard twin, standard twin, family.And after i explode it become array.How want to count the no. of room? $rt = explode(',', $roomtype); how to count the $rt? how to show the standard twin is 2, family is 1? this is my problem.... Qty-----Room Type-----Sales Price-----Room Total Price 1--------Standard Twin-------120.00 ------ 120.00 1--------Standard Twin-------120.00 ------ 120.00 1 ------- Standard Queen ----150.00 ------ 150.00 i want my table look like this..... Qty Room Type Sales Price Room Total Price 2-------Standard Twin-------120.00 ------ 240.00 1 ------- Standard Queen ----150.00 ------ 150.00 can anybody help me... please... i just a little girl in a big world.. please... it in php language

Answers

  1. jmfc

    On 2006-08-09 08:24:14


    you should be able to do this in your query by grouping the data, and not have to do it in your php code, something like this select count(room_type) as quantity, room_type, sales_price, sum(sales_price) as roomTotalPrice from rooms order by room_type group by room_type, sales_price here is a page which has some more 'group by' examples http://www.techonthenet.com/sql/group_by.php good luck