Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 184 Vote(s) - 3.41 Average
  • 1
  • 2
  • 3
  • 4
  • 5
mySQL Query to list number of comments my site received each day?

#1
I run an online magazine and would like a dead-simple way to track 3 metrics:

1. How many comments are left each day.
2. How many links my users submit.
3. How many new members I get each day.

This information is all my database, I'm just not sure how to get it out.

I have a "comments" table with about 3500 comments. Each comment gets a row in the table. One of the columns in the table is "timestamp."

I'm assuming there's a query that will select this table, sort the rows by timestamp, group them in 24-hour increments and then count the number of rows in each group - telling me how many new comments I received each day.

What would that query look like? I think I can figure out the other ones if I had the first one working.
Reply

#2
Use the date_format() function to format the dates;

select count(id) as commentCount, date_format(dateColumn, '%Y-%m-%d') as commentDate
from yourTable
group by commentDate
Reply

#3
This fragment will display your results in a themed table:

$sq = 'SELECT COUNT(*) cnt, DATE(FROM_UNIXTIME(timestamp)) day '
. 'FROM {comments} c '
. 'GROUP BY 2 '
. 'ORDER BY 2 DESC';
$q = db_query($sq);
$stats = array();
while ($o = db_fetch_object($q)) {
$stats[$o->day] = array($o->day, $o->cnt);
}
return theme('table', NULL, $stats));

Using DATE(timestamp) doesn't work because comments.timestamp is in UNIX_TIMESTAMP format, whereas DATE() expects an ASCII date.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through