PHP Mysql Syntax For Count and Select

Posted on 2011-03-21
Last Modified: 2012-06-21

 I want to count and select multiple items in a table.

 I want to select members who opened more than 15 threads in the last 15 days.

 Threadid - userid - dateline are the column names.

How can i select and list these userids?
Question by:mescalin
  • 2

Expert Comment

ID: 35183819
This will do:

SELECT *, COUNT(*) as num_threads FROM `table` WHERE  DATE_SUB(CURDATE(),INTERVAL 15 DAY) <= dateline  GROUP BY `userid` HAVING num_threads > 15 ORDER BY aantal DESC

Open in new window

I'm not sure what kind of value you have in dateline but let me know if this doens't work so you can give me some more detail on that field.

Accepted Solution

Rik-Legger earned 500 total points
ID: 35183822
Correction in query:

SELECT *, COUNT(*) as num_threads FROM `table` WHERE  DATE_SUB(CURDATE(),INTERVAL 15 DAY) <= dateline  GROUP BY `userid` HAVING num_threads > 15 ORDER BY num_threads DESC

Open in new window


Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now