Jump to content

Entries newer than 2 weeks marked with a "new post"


Amarok

Recommended Posts

I would like to pursue a "new post" function that would mark entried to my database newer than 2 weeks with a special graphic or "new post" in red, but I'm not sure how it would work. My "date_post" field has the following - TYPE: timestamp / ATTRIBUTES: ON UPDATE CURRENT_TIMESTAMP / DEFAULT: CURRENT_TIMESTAMP so a particular entry is getting a time stamp that ends up looking like this: 2007-08-23 13:30:17

 

I would like to have the "new post" notification show up only if the entry is less than 2 weeks old. Is this possible? I am sure there is a way to compare the TIMESTAMP to the current time minus 2 weeks, but I have no idea what the syntax would be.

 

Right now my code is as follows:

 

$sql = "SELECT id as id, title
        FROM   main
LIMIT 0, 15
       ";

$result = mysql_query($sql);

if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}

if (mysql_num_rows($result) == 0) {
    echo "No rows found, nothing to print so am exiting";
    exit;
}

while ($row = mysql_fetch_assoc($result)) {
    //echo $row["id"], ' ', $row["title"], '<br />';
    echo '<li><strong>','<a href="details.php?id=', $row[id], '">', $row[title], '</a></strong></li>';

}
echo '</ul>';

 

Link to comment
Share on other sites

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.