Sunday, 24 September 2017

PHP MYSQL how to count items whilst selecting

I've reached a point in my programme where i am stuck.



I would like to have my code so that it selects everything in my database but also counts each duplicate value.



my current mysql code is:



$sql = "SELECT * FROM $country_category ORDER BY stage_limit_timer DESC, contract_name ASC";


This displays my products as follows:





red football

blue football

green football

red football

green football

etc.





I would like my products to be display as:




red football (2)

blue football (1)

green football (2)

red football (2)

green football (2)





I don't want to merge the duplicates just to count them (Would i do this in PHP or mysql?).



Any help with this would be massively appreciated. Thanks

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...