Wednesday, 15 June 2011

php - Implementing code into smarty -



php - Implementing code into smarty -

i new frameworks. , made simple script in php. don't know how can implement code in smarty .tpl file.

// yesterday $hour = 12; $today = strtotime("$hour:00:00"); $yd = strtotime("-1 day", $today); $yesterday = date('d/m/y', $yd); $query = "select date, amount yesterday_deposit"; $fetch_query = mysql_query($query); $total_amount = 0; while($row = mysql_fetch_array($fetch_query)){ $day = $row['date']; if(($dt = date('d/m/y', $day)) === $yesterday){ $total_amount += $row['amount']; } } echo $total_amount;

smarty template engine separate displaying info , other operations.

what should in case is:

// yesterday $hour = 12; $today = strtotime("$hour:00:00"); $yd = strtotime("-1 day", $today); $yesterday = date('d/m/y', $yd); $query = "select date, amount yesterday_deposit"; $fetch_query = mysql_query($query); $total_amount = 0; while($row = mysql_fetch_array($fetch_query)){ $day = $row['date']; if(($dt = date('d/m/y', $day)) === $yesterday){ $total_amount += $row['amount']; } } $smarty->assign('total_amount', $total_amount);

and in smarty template file should simple do:

{$total_amount}

that's way should work. create calculations, info database in pure php files , display info in template files (for illustration in smarty).

in above illustration assume have created smarty object , variable name $smarty , display somewhere else in code template file.

php smarty

No comments:

Post a Comment