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

1
  • 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. Commented Aug 16, 2018 at 9:31

1 Answer 1

2

Something like:

SELECT product, count(*) as count FROM $country_category GROUP BY product
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.