Въпрос за smarty

Styl3rbg

Registered
Понеже в сайта в който ще използвам smarty има система за новини, та се чудя как ще стане да ги извадя в сайта с примерно {$news} , но в php как ще бъде, не намерих в документацията в сайта им ?
 
Ето ти един примерен код.

PHP:
$sql = mysql_query("SELECT * FROM `news` WHERE id='$id'");

//Putting the results into an array
while($row = mysql_fetch_array($sql)){
	//Putting the result into a smarty array
	$result[] = $row;}

//Assing some smarty variables
$smarty->assign("result",$result);

//Display the template file
$smarty->display("index.tpl");

След което в .tpl файла ще го вадиш така:

Код:
{foreach item="r" from="$result"}
  {$r.id}<br /> 
  {$r.name}<br />
{/foreach}

И така на татък.
 
qazxsw каза:
Ето ти един примерен код.

PHP:
$sql = mysql_query("SELECT * FROM `news` WHERE id='$id'");

//Putting the results into an array
while($row = mysql_fetch_array($sql)){
	//Putting the result into a smarty array
	$result[] = $row;}

//Assing some smarty variables
$smarty->assign("result",$result);

//Display the template file
$smarty->display("index.tpl");

След което в .tpl файла ще го вадиш така:

Код:
{foreach item="r" from="$result"}
  {$r.id}<br /> 
  {$r.name}<br />
{/foreach}

И така на татък.
Мерси :P
 

Back
Горе