Friday, July 24, 2009

Smarty Date display problem inside Table

Ciao tutti,

When you display a big Date (date with time) from MySQL to a table using smarty, Smarty ends up showing NULL as value. You can follow these tips..

a) apply DATE function inside query.
b) use date_format:"d":"m":"Y" to show date as DD:MM:YY format. Remember if you want the output as DD-MM-YY you need date_format:"d"-"m"-"YY" so the idea is to put the seperator value in format like (: or / or -).

Example Query : SELECT DATE(yourdate column), name FROM yourTable WHERE condition.

Example Smarty display: (using section for tabular view)...

{section name=id loop=$Myresults}
table_row class="{cycle}"> {* Comment: If you want a odd even printing *}
table_data{$Myresults[id].name}/table_data
table_data{$Myresults[id].yourdate|date_format:"%d/%m/%Y"} /table_data

End table_row
{sectionelse}
table_row table data Nothing to display table data /table_row
{/section}

PS: Replace table_row with "tr" and tabledata with "td" ofcourse with angle brackets as blog was unable to show the html.
hope this helps someone.. enjoy !!

No comments:

Post a Comment