Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hello,

 

I am having a strange problem. My year is showing up as just first number, so '1997' is '1'.. simple problem I am sure but can't find it. Tried changing my database from 'year' format to 'date and to datetime, but that does not work. In My 'q' I call: DATE_FORMAT(p.year_complete, '%Y'), I change my filed name to AS $year blah blah,.. and then my echo is added in to the painting description:

 

if (!empty($p_description)) {

echo "<p>$p_description</p><br />Original Painting Completed: {$year['year']}</p>\n";

}

 

 

I read on page 163 TIP 'always use MySQL functions to format any dates coming from the database'.

 

 

What am I missing?

Link to comment
Share on other sites

I'm unclear on how your date is stored in the database. Is the value stored in year_complete 1997, or 1997-11-03? If it's just 1997 you don't need to perform any date formats. If it's a full date, you can extract just the year portion by using YEAR(p.year_complete).

 

It also looks like you are storing the year in an array in PHP. For debugging, print out the contents of the array to see if it holds what you expect it to:

 

echo "<pre>\n";
print_r ($year);
echo "</pre>\n";

What does that output look like?

  • Upvote 1
Link to comment
Share on other sites

Ok, output is working. I did have an array problem. Not sure exactly what happened but it is working. I split up the description and year; always a chance I would leave out a description but have the year in data so needed to be in two echo's anyway.

 

Thank You!!!!

Link to comment
Share on other sites

 Share

×
×
  • Create New...