Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

[b]newbie: passing array to .tpl from mysql_fetch_array[/b]

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
shawnhirtle
Smarty n00b


Joined: 23 Jul 2003
Posts: 2

PostPosted: Wed Jul 23, 2003 2:00 pm    Post subject: [b]newbie: passing array to .tpl from mysql_fetch_array[/b] Reply with quote

I know this may sound stupid, but I'm new to Smarty. I am trying to pass an array I'm getting by using the mysql_fetch_array() function. I want to pass the results to the template and display each one in it's own table row in the template.

My php code is:
$db_data = @ mysql_fetch_array($result);
$smarty->assign('db_data',$db_data);

My .tpl page looks like this (but is obviously wrong...):
<table align="center" width="800">
{section name=news loop=$db_data}
<tr>
<td>
<h3>{$db_data[title]}</h3>
<p>{$db_data[brief]}</p>
<a href="details.php?news_ID=$news_ID">Read more...</a>
<p>Posted by {$db_data[user_name]} on {$db_data[date_added]}.</p>
</td>
</tr>
{/section}
</table>

any help would be much appreciated. I'm still learning the tricks and this problem has got me stuck Confused
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Jul 23, 2003 2:05 pm    Post subject: Reply with quote

there is a tutorial that covers exactly this: http://www.codeforsoup.com/edu/smarty.php Smile

HTH
messju
Back to top
View user's profile Send private message Send e-mail Visit poster's website
shawnhirtle
Smarty n00b


Joined: 23 Jul 2003
Posts: 2

PostPosted: Wed Jul 23, 2003 2:08 pm    Post subject: Reply with quote

thanks so much. I needed that Very Happy
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Jul 23, 2003 2:09 pm    Post subject: Reply with quote

hmm, i think you just want to say $db_data[news].title, $db_data[news].brief etc. (the section-name goes between "[]", but array-keys are seperated by ".").

nontheless, the tutorial above may be a good read anyway.

greetings
messju
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP