Jump to content

Recommended Posts

In my website, I have created a forum like system where people post etc..

 

I'm trying to think of the best way for the script to know how fresh the topic is (i.e. how long ago was the last post) and thus place it at the top

 

In other words, I have made a column im mysql called 'lastpost' and i don't know whats the best php function to use..

 

can you help?

There are two ways to do this:

1. Use the mysql function NOW() to insert the current timestamp into a timestamp column. 

 INSERT INTO table (column1,column2,lastpost) VALUES ('column','column',NOW());

2. You can set the column to default to the current timestamp.  This will eliminate the need to tell mysql to put anything in that column.

CREATE TABLE IF NOT EXISTS `table` (
  `column1` varchar(20) NOT NULL,
  `column2` varchar(20) NOT NULL,
  `lastpost` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);

 

My suggestions at least.

 

jcbones explained it very well, but in the future you should probably post the code you are trying to use that is giving you trouble. Also, doing a little research on the proper technique to use is always a good way to get an answer. In your case, simply searching "mysql timestamp tutorial" or something like that would have probably yielded some useful results

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.