954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

"SELECT date FROM posts WHERE user = user" MySQL?

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!

calebcook
Junior Poster in Training
66 posts since Jun 2011
Reputation Points: 10
Solved Threads: 4
 

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 (?)

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

works fine-thanks!

calebcook
Junior Poster in Training
66 posts since Jun 2011
Reputation Points: 10
Solved Threads: 4
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: