|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Mystic` Smarty n00b
Joined: 30 Apr 2003 Posts: 2
|
Posted: Wed Apr 30, 2003 12:47 am Post subject: I want to pass an array to smarty |
|
|
Hi there.
First smarty is great !
Second : i've a prob with it
I want print some news, si i make an array with this :
Code: | $i=0;
WHILE(($get_news = mysql_fetch_object($req)) and ($i <= 3)) // only 4 news
{
$news[$i][id] = $get_news->id;
$news[$i][name] = $get_news->name;
$news[$i][date] = date("m/d/y H:i",$get_news->date);
$news[$i][titre] = $get_news->titre;
$news[$i][text] = replace_balises($get_news->text);
$i++;
} |
That's give me a array, and i want to pass this array in smarty.
I've try
Code: |
WHILE(($get_news = mysql_fetch_object($req)) and ($i <= 3)) //on veut que 4 news
{
$date = date("m/d/y H:i",$get_news->date);
$text = replace_balises($get_news->text);
$smarty->assign("news[$i]",array("$get_news->id",
"$get_news->name",
"$date",
"$get_news->titre",
"$text"
)
);
$i++;
}
|
and
Code: |
$smarty->assign("news","$news");
|
but both dont work...
i've search in faq and manual, i dont find how to put $news php's variable into $news smarty's variable with the same structure.
Help.
Jeremy
PS: var_dump of $news can be see here : http://mystic.phpnet.org/tmp/var_dump.htm |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Apr 30, 2003 12:54 am Post subject: |
|
|
Try this:
::EDIT::
Code: | WHILE(($get_news = mysql_fetch_object($req)) and ($i <= 3)) //on veut que 4 news
{
$date = date("m/d/y H:i",$get_news->date);
$text = replace_balises($get_news->text);
$news[] = array("$get_news->id",
"$get_news->name",
"$date",
"$get_news->titre",
"$text"
);
$i++;
}
$smarty->assign_by_ref('news', $news);
|
ps. bonjour! |
|
Back to top |
|
Mystic` Smarty n00b
Joined: 30 Apr 2003 Posts: 2
|
Posted: Wed Apr 30, 2003 11:13 am Post subject: yep it's work ! |
|
|
that work fine ! thanks a lot boots !
Helloooooooooooooooooooooooooooooooooo |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|