I'm trying to create a message board where members can post messages to other members. I'd like to have a section where it says "4 posts since Jan 2011" just like DaniWeb does. How do I get the date from the

"first row WHERE user='username'"

with PHP & MySQL? Also, I'd like to show if the user is online. Is that possible with PHP?
Thanks!

Recommended Answers

All 2 Replies

Member Avatar for diafol

Online user is difficult as users don't always log out. If you store session data in a DB or even lastpageaccess field, you can approximate if an user has been active in the last 10, 20 mins etc.

If your dates are stored in integer format (unix timestamp), you can set the target date using mktime() and see if post dates are >= to the target:

$targetdate = mktime(0,0,0,1,1,2011); //from midnight 1/1/2011 (hr,min,sec,mnth,day,yr)

Then the SQL:

SELECT count(*) FROM `table` WHERE `postdate` >= $targetdate

You can select a specific field for the count part - it may be faster (?)

works fine-thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.