Page 1 of 1

PHP Date Converter script not working

Posted: Wed Feb 17, 2010 8:20 pm
by jthermane24
I'm trying to write a script that converts a unix timestamp to date time, with php, and displays it along with the title it's corresponding article. Now matter how hard, or how many different combinations, I try I can't get it to work and keep getting prompted with the same Prase Error. Can anyone look at the script and error pasted below and point me in the right direction? Thanks for the help.

Code: Select all

Parse error: syntax error, unexpected T_STRING in /xxxxx/htdocs/RecentNews.php on line 14

Code: Select all

<?php
// Standard functions
require('functions.php');
 
// Connect to the database
database_connect('Admin');
 
// Set up the query and run it
$sql = "SELECT * FROM `cmsarticles` LIMIT 0, 5 ";
$result = mysql_query($sql) or die(mysql_error());
 
// Start echo of list
echo'<ul>';
 
while ($row = mysql_fetch_array($result)) {
    $timestamp = $row['date'];
    $timestamp = date(F d Y,$timestamp);    
    echo'<li><h3>' . $timestamp . '</h3><p><a href="../admin/viewarticle.php?id=' . $row['ID'] . '">' .     $row['title'] . '</a></p></li>';
}
 
echo'</ul>';
    
?>

Re: PHP Date Converter script not working

Posted: Wed Feb 17, 2010 10:19 pm
by califdon
For one thing, you need quotation marks around the pattern part of your date() call:
$timestamp = date('F d Y',$timestamp);

If there are still problems, they may be in the included "functions.php" file, which you haven't shown to us.

Re: PHP Date Converter script not working

Posted: Wed Feb 17, 2010 10:29 pm
by jthermane24
califdon wrote:For one thing, you need quotation marks around the pattern part of your date() call:
$timestamp = date('F d Y',$timestamp);

If there are still problems, they may be in the included "functions.php" file, which you haven't shown to us.
Unbelievable that I missed that, the fix worked, it's always the simple things that you have to look over. Thanks.