phprocker Posted January 23, 2010 Share Posted January 23, 2010 Hey all. I have a database table that adds the date every time someone clicks on a specific link. So if 5 people click on this link on January 10 it will add 5 Jan 10th dates to the "click_date" column and so forth. So, I'm retrieving this lists of dates from the database table and grouping them with the GROUP BY statement. This is fine and the dates get listed all grouped but how can I list the number of rows each group has? So it lists like this: Jan 10th - 5 Clicks Jan 11th - 3 Clicks Here's the code I'm using: sql = "SELECT * FROM clicktrack WHERE link='$link' GROUP BY click_date"; So I have no problem listing the dates as so: Jan 10th Jan 11th But I need the number in each group of dates. Thanks. Link to comment https://forums.phpfreaks.com/topic/189543-counting-grouped-table-column-results/ Share on other sites More sharing options...
spfoonnewb Posted January 23, 2010 Share Posted January 23, 2010 Try this: sql = "SELECT `click_date`, COUNT(*) FROM clicktrack WHERE link='$link' GROUP BY click_date"; Link to comment https://forums.phpfreaks.com/topic/189543-counting-grouped-table-column-results/#findComment-1000470 Share on other sites More sharing options...
phprocker Posted January 23, 2010 Author Share Posted January 23, 2010 OK. It didn't break the SQL...but how do I access the group counts? Link to comment https://forums.phpfreaks.com/topic/189543-counting-grouped-table-column-results/#findComment-1000485 Share on other sites More sharing options...
phprocker Posted January 23, 2010 Author Share Posted January 23, 2010 Never mind I got it. It was: sql = "SELECT `click_date`, COUNT(*) AS clicks FROM clicktrack WHERE link='$link' GROUP BY click_date"; Thanks much. Link to comment https://forums.phpfreaks.com/topic/189543-counting-grouped-table-column-results/#findComment-1000490 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.