0

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

Hari Krishnan
  • 2,049
  • 2
  • 18
  • 29
  • Sorry but if you have more than one of these results that query does not show what you say it does without being processed in some way by your PHP code. – RiggsFolly Aug 16 '18 at 09:31

1 Answers1

2

Something like:

SELECT product, count(*) as count FROM $country_category GROUP BY product
danblack
  • 12,130
  • 2
  • 22
  • 41