Jump to content

Recommended Posts

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  :D

 

Edit the date should be displayed liek this: day, month day_int, year

Link to comment
https://forums.phpfreaks.com/topic/108746-solved-error-in-code-display-date-code/
Share on other sites

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 :D

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?

 

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

@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 :)

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.