xoligy Posted June 4, 2008 Share Posted June 4, 2008 Ok i followed a tutorial for a news system with comments and got it working, but i wasn';t pleased with how the date was displaying so i found another date system on another tutorial and im trying to add it to this one but carnt get it to work It's error is on line 47 and commented // <?php $query = "SELECT id, title, author, post, year, month, day, day_int, time FROM news_posts ORDER BY by id DESC LIMIT 5"; $result = @mysql_query($query); if ($result) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $day = $news_posts[day]; $day_int = $news_posts[day_int]; $month = $news_posts[month]; $year = $news_posts[year]; $time = $news_posts[time]; $url = 'comments.php?id='.$row['id']; echo '<table width=98% align=center> <TH align=left style="font-size: 11px;">'.$row['day'], .$row['month'] .$row['day_int'], .$row['year'].'</TH> // this is the culprit! <TR><TD width="98%"><p><b style="font-size: 16px;">'.$row['title'].'</b></TD> <TR><TD style="font-size: 11px;">Posted by : <b><a href="#">'.$row['author'].'</a></b></TD> <TR><TD style="padding: 15px;"><p>'.$row['post'].'</TD> <TR><TD><a href="javascript:openComments(\''.$url.'\')">Add new comment or view posted comments</a></p></TD></TR> </table>'; } } else { echo 'There are no news posts to display'; } ?> I'll be back with more problems no doubt as there are two other things im trying to figure out too... not just on this page but also the submit page Edit the date should be displayed liek this: day, month day_int, year Quote Link to comment https://forums.phpfreaks.com/topic/108746-solved-error-in-code-display-date-code/ Share on other sites More sharing options...
Caesar Posted June 4, 2008 Share Posted June 4, 2008 How is the date displaying and what about it don't you like? Basically, what's your goal? Quote Link to comment https://forums.phpfreaks.com/topic/108746-solved-error-in-code-display-date-code/#findComment-557697 Share on other sites More sharing options...
xoligy Posted June 4, 2008 Author Share Posted June 4, 2008 There is no date displaying now because i canna figure out how to add it, before it was added like day, month year and want it day, month day_int, year the date code has been changed by me with new code you see :/ Quote Link to comment https://forums.phpfreaks.com/topic/108746-solved-error-in-code-display-date-code/#findComment-557699 Share on other sites More sharing options...
revraz Posted June 4, 2008 Share Posted June 4, 2008 You are doing it the hard way. Just use a DateTime field or a Unix timestamp and then use date() to display it in any format you like. Quote Link to comment https://forums.phpfreaks.com/topic/108746-solved-error-in-code-display-date-code/#findComment-557700 Share on other sites More sharing options...
xoligy Posted June 4, 2008 Author Share Posted June 4, 2008 Trust me to find bloody hard code haha im a noob o.0 Quote Link to comment https://forums.phpfreaks.com/topic/108746-solved-error-in-code-display-date-code/#findComment-557701 Share on other sites More sharing options...
discomatt Posted June 4, 2008 Share Posted June 4, 2008 Proper error debugging is a very important tool in a programmer's chest. Isolate the error to a specific line of code ( remove lines one by one until the error is gone ). Once you've narrowed it down that far, isolate it to a specific statement using similar methods. Just because PHP found an error on x line doesn't mean the problematic code is on that line, or for that matter, anywhere near it. I also recommend grabbing the PHP build of the Eclipse IDE (PDT) http://www.eclipse.org/pdt/ It's a great environment that can be set up for real-time debugging. Best part is it's free Quote Link to comment https://forums.phpfreaks.com/topic/108746-solved-error-in-code-display-date-code/#findComment-557702 Share on other sites More sharing options...
revraz Posted June 4, 2008 Share Posted June 4, 2008 See if this helps or confuses you more. http://us3.php.net/date Quote Link to comment https://forums.phpfreaks.com/topic/108746-solved-error-in-code-display-date-code/#findComment-557705 Share on other sites More sharing options...
xoligy Posted June 4, 2008 Author Share Posted June 4, 2008 I understand bits and bobs of it, before i changed the code the addnews page used the Now() to store the date so i guess i can change that back and then use the datebase to get the date like $query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %jS %Y') as sd FROM news_posts ORDER BY date DESC LIMIT 5"; then put the code to display the date back to '.$row['sd'].' Woudl that work? Quote Link to comment https://forums.phpfreaks.com/topic/108746-solved-error-in-code-display-date-code/#findComment-557718 Share on other sites More sharing options...
xoligy Posted June 4, 2008 Author Share Posted June 4, 2008 The if i wated to display time it be date(h:i A) yes? Quote Link to comment https://forums.phpfreaks.com/topic/108746-solved-error-in-code-display-date-code/#findComment-557723 Share on other sites More sharing options...
craygo Posted June 4, 2008 Share Posted June 4, 2008 it is a good practice to keep your field and table names in ticks and values in single quotes. For good reason, you have a field named "date". It is a reserved word and you may get errors. Words like order and group will also give problems. so good practice to do this $query = "SELECT `id`, `title`, `author`, `post`, DATE_FORMAT(`date`, '%M %d, %jS %Y') as `sd` FROM` news_post`s ORDER BY `date` DESC LIMIT 5"; Ray Quote Link to comment https://forums.phpfreaks.com/topic/108746-solved-error-in-code-display-date-code/#findComment-557724 Share on other sites More sharing options...
xoligy Posted June 4, 2008 Author Share Posted June 4, 2008 Ok thanks Ray, like i said i just followed the tut i'll sort it all out now thanks! Quote Link to comment https://forums.phpfreaks.com/topic/108746-solved-error-in-code-display-date-code/#findComment-557729 Share on other sites More sharing options...
revraz Posted June 4, 2008 Share Posted June 4, 2008 The tutorial adivsed to use "Date" as a fieldname for the DB? Quote Link to comment https://forums.phpfreaks.com/topic/108746-solved-error-in-code-display-date-code/#findComment-557730 Share on other sites More sharing options...
xoligy Posted June 4, 2008 Author Share Posted June 4, 2008 Thats it there http://www.tutorialcode.com/php/news-system-with-comments/ Quote Link to comment https://forums.phpfreaks.com/topic/108746-solved-error-in-code-display-date-code/#findComment-557731 Share on other sites More sharing options...
revraz Posted June 4, 2008 Share Posted June 4, 2008 Ah that's right, Date isn't a reserved word. Quote Link to comment https://forums.phpfreaks.com/topic/108746-solved-error-in-code-display-date-code/#findComment-557742 Share on other sites More sharing options...
xoligy Posted June 4, 2008 Author Share Posted June 4, 2008 @Revraz, lol Ray@ when i used your $query string it didnt like it lol just thought let you know had to put it back to $query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts"; i think i got the jS wrong too so gonna sort that out Quote Link to comment https://forums.phpfreaks.com/topic/108746-solved-error-in-code-display-date-code/#findComment-557749 Share on other sites More sharing options...
craygo Posted June 4, 2008 Share Posted June 4, 2008 lol sorry thats cause I messed this up ` news_post`s my bad $query = "SELECT `id`, `title`, `author`, `post`, DATE_FORMAT(`date`, '%M %d, %jS %Y') as `sd` FROM `news_posts` ORDER BY `date` DESC LIMIT 5"; Quote Link to comment https://forums.phpfreaks.com/topic/108746-solved-error-in-code-display-date-code/#findComment-557755 Share on other sites More sharing options...
xoligy Posted June 4, 2008 Author Share Posted June 4, 2008 Aaah ok thanks Quote Link to comment https://forums.phpfreaks.com/topic/108746-solved-error-in-code-display-date-code/#findComment-557759 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.