简体   繁体   中英

Counting amount of db rows of a user using timestamp - Best approach?

This might sound quite stupid, but whats the best approach to count a users db entries of today, so I can publish the most activate member with mysqli?

Thanks..

Edited; Current code

$promote_amount_posts = mysqli_query($mysqli,"SELECT COUNT(rec_by_id) FROM posts LIMIT 1 "); 
$row = mysqli_fetch_assoc($promote_amount_posts);
$promote_amount_posts = $row['COUNT(rec_by_id)'];
$most_active_user_id = $row['rec_by_id'];

Lets say my user_id (which goes into the rec_by_id column) is 82392 and I created 20 posts. There should be atlease MY 20 posts in the 'posts' table. How do I fetch my user_id so I can echo it anywhere?

The following query should return the count in today_db_entries as long as you have a created column and a id column - swap out those names for whatever your schema uses.

SELECT COUNT(id) as today_db_entries 
FROM table 
WHERE created BETWEEN getdate() AND getdate()-1 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM