siafulinux Posted October 12, 2007 Share Posted October 12, 2007 Okay, here's a quick question. I am somewhat new to PHP but have created an application but am stuck at how to do something. I have a table with entries and a date stamp in mm/dd/yyyy format. I want to count how many days there were but only counting 1 day if there are say 20 entries for one specific day! In other words lets say there are: 10 entries for 10/05/2007 and 5 entries for 10/10/2007 The count should result as 2 days. I have tried while loops but they keep causing the browser to not load the page. Here is an example of what I've tried: // GET THE NUMBER OF DAYS FOR ENTRIES $query = "SELECT (date) AS date FROM data"; $result = mysql_query($query) or die(mysql_error()); // EXECUTE THE ABOVE QUERY $number = 0; while ($row = mysql_fetch_array($result)){ while ($row['date'] == $row['date']) { // Also tried if ($row['date'] == $row['date']) { $number = $number + 1; echo $number; } } Can anyone help with this? Much appreciated. Siafu Quote Link to comment https://forums.phpfreaks.com/topic/72966-count-number-of-days-in-db-by-date-listed/ Share on other sites More sharing options...
Barand Posted October 12, 2007 Share Posted October 12, 2007 SELECT COUNT(DISTINCT date) as num_days FROM data Quote Link to comment https://forums.phpfreaks.com/topic/72966-count-number-of-days-in-db-by-date-listed/#findComment-367968 Share on other sites More sharing options...
siafulinux Posted October 13, 2007 Author Share Posted October 13, 2007 SELECT COUNT(DISTINCT date) as num_days FROM data Awesome... works wonderfully! Thanks Barand! Quote Link to comment https://forums.phpfreaks.com/topic/72966-count-number-of-days-in-db-by-date-listed/#findComment-368599 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.