|
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 |
shawnhirtle Smarty n00b
Joined: 23 Jul 2003 Posts: 2
|
Posted: Wed Jul 23, 2003 2:00 pm Post subject: [b]newbie: passing array to .tpl from mysql_fetch_array[/b] |
|
|
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 |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
|
Back to top |
|
shawnhirtle Smarty n00b
Joined: 23 Jul 2003 Posts: 2
|
Posted: Wed Jul 23, 2003 2:08 pm Post subject: |
|
|
thanks so much. I needed that |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Jul 23, 2003 2:09 pm Post subject: |
|
|
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 |
|
|
|
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
|