doctor_james Posted October 9, 2008 Share Posted October 9, 2008 I've created a table to save my website visits , the fields are id,Ip,date,page,broswer . By each visit , a Record are added to the table so each day can have several records. Now I wanted to get this Information out of these Information: 1) Hits for the busiest day . 2) Hits for this week. 3) Hits for this month. 4) Hits for this year. How can I do it ? Is this possible with the information I've collected ? Thanks in advance . Quote Link to comment https://forums.phpfreaks.com/topic/127647-how-can-i-get-these-results-out-of-my-table/ Share on other sites More sharing options...
refiking Posted October 9, 2008 Share Posted October 9, 2008 sure you can get those results //Assuming your db table's name is table and your timestamp is named stamp: // For all the hits of the month $sql = mysql_query("SELECT * FROM `table` WHERE MONTH(`stamp`) = '10' AND YEAR(`stamp`) = '2008'"); // For all the hits of the year $sql = mysql_query("SELECT * FROM `table` WHERE YEAR(`stamp`) = '2008'"); Can't think of the best route to get the busiest day right now, but yeah if you get the data you say you are, that's all you need to pull these records Quote Link to comment https://forums.phpfreaks.com/topic/127647-how-can-i-get-these-results-out-of-my-table/#findComment-660560 Share on other sites More sharing options...
Maq Posted October 9, 2008 Share Posted October 9, 2008 Check out Count(*). It allows you to collect the number of records for your desired condition. There's plenty of examples online. Quote Link to comment https://forums.phpfreaks.com/topic/127647-how-can-i-get-these-results-out-of-my-table/#findComment-660567 Share on other sites More sharing options...
doctor_james Posted October 9, 2008 Author Share Posted October 9, 2008 Thanks for the replies .. I used your method but It returns no result. Quote Link to comment https://forums.phpfreaks.com/topic/127647-how-can-i-get-these-results-out-of-my-table/#findComment-660589 Share on other sites More sharing options...
trq Posted October 9, 2008 Share Posted October 9, 2008 You might want to post your current code. Quote Link to comment https://forums.phpfreaks.com/topic/127647-how-can-i-get-these-results-out-of-my-table/#findComment-660590 Share on other sites More sharing options...
doctor_james Posted October 9, 2008 Author Share Posted October 9, 2008 $query="SELECT DISTINCT(ip) FROM stats WHERE YEAR('date')='2008'"; $h=mysql_query($query); $hits=mysql_num_rows($h); Quote Link to comment https://forums.phpfreaks.com/topic/127647-how-can-i-get-these-results-out-of-my-table/#findComment-660593 Share on other sites More sharing options...
Stooney Posted October 9, 2008 Share Posted October 9, 2008 Try changing ('date') to this: (`date`) Quote Link to comment https://forums.phpfreaks.com/topic/127647-how-can-i-get-these-results-out-of-my-table/#findComment-660595 Share on other sites More sharing options...
doctor_james Posted October 9, 2008 Author Share Posted October 9, 2008 Try changing ('date') to this: (`date`) It worked , thanks alot. But there's still one question left. How can I get the hits for the busiest day according to the table I introdiced above . Thank You all . Quote Link to comment https://forums.phpfreaks.com/topic/127647-how-can-i-get-these-results-out-of-my-table/#findComment-660596 Share on other sites More sharing options...
trq Posted October 9, 2008 Share Posted October 9, 2008 Did you look at mysql's COUNT function? Quote Link to comment https://forums.phpfreaks.com/topic/127647-how-can-i-get-these-results-out-of-my-table/#findComment-660598 Share on other sites More sharing options...
doctor_james Posted October 9, 2008 Author Share Posted October 9, 2008 Did you look at mysql's COUNT function? Yes, I have.. I want to count the records of the busiest day But I really have no Idea how to do it . Quote Link to comment https://forums.phpfreaks.com/topic/127647-how-can-i-get-these-results-out-of-my-table/#findComment-660599 Share on other sites More sharing options...
xylex Posted October 9, 2008 Share Posted October 9, 2008 SELECT COUNT(*) FROM stats GROUP BY DAYNAME(`date`); Quote Link to comment https://forums.phpfreaks.com/topic/127647-how-can-i-get-these-results-out-of-my-table/#findComment-660661 Share on other sites More sharing options...
Maq Posted October 9, 2008 Share Posted October 9, 2008 SELECT COUNT(*) FROM stats GROUP BY DAYNAME(`date`); Then if you grab the first record it should have the highest count, being the busiest day. Quote Link to comment https://forums.phpfreaks.com/topic/127647-how-can-i-get-these-results-out-of-my-table/#findComment-660663 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.