TinyPortal

Development => Support => Topic started by: DonaldDasher on October 24, 2008, 02:48:04 PM

Title: Article Creation Date in Block errors
Post by: DonaldDasher on October 24, 2008, 02:48:04 PM
Can anybody help - most articles have the same date as the creation date in th list but it's correct on the actual articles.

Here's the block codes:

global $db_prefix, $scripturl, $user_info;

$query = db_query(
    "SELECT subject, id, date, shortname
     FROM {$db_prefix}tp_articles
     WHERE approved = 1
     ORDER BY date DESC
     LIMIT 20", __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($query))
{
  if(empty($row['shortname'])) $row['shortname'] = $row['id'];

echo '<font size="1pt"><b><a href="' . $scripturl . '?page=' . $row['shortname'] . '">' . $row['subject'] . '</a></b><br>- '. date("M n, Y - g:ia", $row['date']) . '</font><br />';
}


http://www.pre-cert.co.uk/
Title: Re: Article Creation Date in Block errors
Post by: Ianedres on October 24, 2008, 03:07:23 PM
There is only one date field in 0.98 articles; the SQL query *should* be ordering the results as such (numerically so that the highest timestamp appears first in your list) but I see on your site it is not...
Title: Re: Article Creation Date in Block errors
Post by: DonaldDasher on October 24, 2008, 03:11:20 PM
Indeed - it's a mystery.
Title: Re: Article Creation Date in Block errors
Post by: JPDeni on October 24, 2008, 04:41:05 PM
You have a problem in your date function:


date("M n, Y - g:ia", $row['date'])


n is the code for the umeric representation of a month, without leading zeros. So, for articles created in October, it will always print out "Oct 10" and for articles created in September, it will always print out "Sep 9." You need to change it to


date("M j, Y - g:ia", $row['date'])


All of the formatting options are given here (http://us.php.net/date).
Title: Re: Article Creation Date in Block errors
Post by: DonaldDasher on October 24, 2008, 04:51:45 PM
Fabulous - much appreciated. All is now working.  ;)
Title: Re: Article Creation Date in Block errors
Post by: Ianedres on October 24, 2008, 06:17:58 PM
Thanks JPD. Couldn't see the trees for the forest type of thing there...
Title: Re: Article Creation Date in Block errors
Post by: JPDeni on October 24, 2008, 06:37:14 PM
Happens to me all the time. That's the advantage of having a number of people available to look at things.