marksie1988 Posted May 24, 2007 Share Posted May 24, 2007 ok i changed my database from mysql timestamp to and int(11) so that i could use unix_timestamp, i then entered the correct dates for the posts, but all the code displays is the unix timestamp for 1st jan 1970 look here to understand what the php is doing http://blacklimecomputers.co.uk/news/ basically it displays news articles that i enter into a database which has this structure: maybe the database (postdate) isnt correct for a unix timestamp? CREATE TABLE `news` ( `id` int(10) unsigned NOT NULL auto_increment, `postdate` int(11) default NULL, `title` varchar(50) NOT NULL, `newstext` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=34 ; here is the php code maybe you can see whats causing the data to show the timestamp 0 date <?php if($HTTP_GET_VARS['view'] == "archives") { $bl_query = "SELECT * FROM newsarchive order by postdate"; $bl_result = @mysql_query($bl_query) or die(mysql_error()); echo "<h3>Archives</h3><center><a href='../news/rss.php'><img src='../images/rss.png' style='border-style: none'></a></center> <h5 class=\"style2\">see our <a href='../news/index.php'>News</a> for all news newer than 30days.</h5>"; if(mysql_num_rows($bl_result) == 0) { echo "<h5 class=\"style2\">There is no news in the archive</h5>"; } else{ while ($row = mysql_fetch_assoc ($bl_result)) { /* place table row data in * easier to use variables. * Here we also make sure no * HTML tags, other than the * ones we want are displayed */ $date = gmdate("y-m-d h:i:s"); $title = htmlentities ($row['title']); $news = nl2br (strip_tags ($row['newstext'], '<a><b><i><you>')); /* display the data */ $td = "<td align=\"left\" >"; $ttl = "align=\"center\" style=\"font-size:15px; color:#ffffff; font-family:tahoma\""; $dte = "align=\"center\" style=\"font-size:10px; color:#999999; font-family:tahoma\""; $nws = "align=\"center\" style=\"font-size:12px; color:#999999; font-family:tahoma\""; echo "<strong $ttl> \n $title </strong>\n <br>\n"; echo "<strong $dte> \n $date </strong>\n <br>\n"; echo "<strong $nws> \n $news </strong>\n <br><br>\n"; } } } else{ echo "<h3>News</h3><center><a href='../news/rss.php'><img src='../images/rss.png' style='border-style: none'></a></center> <h5 class=\"style2\">see our <a href='../news/index.php?view=archives'>Archives</a> for all news older than 30days </h5>"; /* user config variables */ global $db; $query = "SELECT id, postdate,title,newstext," . "DATE_FORMAT(postdate, '%Y-%m-%d %H:%i:%s') as date " . "FROM news ORDER BY postdate DESC"; $result = mysql_query ($query); if(mysql_num_rows($result) == 0) { echo "<h5 class=\"style2\">There is no news to display</h5>"; } else{ while ($row = mysql_fetch_assoc ($result)) { /* place table row data in * easier to use variables. * Here we also make sure no * HTML tags, other than the * ones we want are displayed */ $date = strftime( "%a, %d %b %Y %T %Z" , $result['postdate']); $title = htmlentities ($row['title']); $news = nl2br (strip_tags ($row['newstext'], '<a><b><i><you>')); /* display the data */ $td = "<td align=\"left\" >"; $ttl = "align=\"center\" style=\"font-size:15px; color:#ffffff; font-family:tahoma\""; $dte = "align=\"center\" style=\"font-size:10px; color:#999999; font-family:tahoma\""; $nws = "align=\"center\" style=\"font-size:12px; color:#999999; font-family:tahoma\""; echo "<strong $ttl> \n $title </strong>\n <br>\n"; echo "<strong $dte> \n $date </strong>\n <br>\n"; echo "<strong $nws> \n $news </strong>\n <br><br>\n"; } } } ?> if you could help me out on how to get it showing the correct date that would be great as it will also fix my rss feed Cheers Steve p.s. im new here so please be gentle:) Quote Link to comment https://forums.phpfreaks.com/topic/52809-solved-unix_timestamp-help/ Share on other sites More sharing options...
craygo Posted May 24, 2007 Share Posted May 24, 2007 Your date is not correct $date = date("y-m-d h:i:s", $row['postdate']); Ray Quote Link to comment https://forums.phpfreaks.com/topic/52809-solved-unix_timestamp-help/#findComment-260707 Share on other sites More sharing options...
marksie1988 Posted May 24, 2007 Author Share Posted May 24, 2007 my gosh i cant belive it was so simple hehe well i am learning from my mistakes and i guess thats the best way to learn Quote Link to comment https://forums.phpfreaks.com/topic/52809-solved-unix_timestamp-help/#findComment-260714 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.