Template Smarty - how to get mysql result set into template table?

[size=2]I have the following query, which returns several rows:

 $query = "SELECT * FROM news WHERE section1='1' ORDER BY timestamp DESC LIMIT 3;";[/size]
[size=2]$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); 

How can I use Template Smarty to generate a table with all the rows and colums from the query[/size]?

I can only figure out display one row using the mysql_fetch_array($result) function, but I need to display a table with ALL the returned rows from the query.


I don’t know if smarty has special support for query

but you can make it with foreach;

	{foreach key=key item=item from=$list_array}
		{foreach key=key2 item=item2 from=$item}

do something like this in the template:

<!--{section name=news loop=$NID}-->
<table width="100%" border="0" cellspacing="0" cellpadding="5">
 <td colspan="3" class="tablehead">{$CATAGORY_TITLE[news]}<b>{$NEWS_TITLE[news]}</b></td>
 <td valign="TOP">
 <table clear="ALL" width="" border="0" cellspacing="0" cellpadding="2" align="right" valign="TOP">
  <td><img src="images/topics/{$TOPIC_IMAGE[news]}" border=0 alt="{$TOPIC_TEXT[news]}"></td>
<table width="100%" border="0" cellspacing="0" cellpadding="1" bgcolor="#004000">
 <td width="150" bgcolor="#004200" class="tablehead">&nbsp;By: {$AUTHOR[news]}</td>
 <td align="CENTER" bgcolor="#004200" class="tablehead">Posted: {$TIME[news]}</td>
 <td width="150" align="RIGHT" class="tablehead">{$MORELINK[news]}</td>

That’s what I used in my template when I use to use smarty.

here’s an example from smarty

{section name=customer loop=$custid}
id: {$custid[customer]}<br>
name: {$name[customer]}<br>
address: {$address[customer]}<br>


id: 1000<br>
name: John Smith<br>
address: 253 N 45th<br>
id: 1001<br>
name: Jack Jones<br>
address: 417 Mulberry ln<br>
id: 1002<br>
name: Jane Munson<br>
address: 5605 apple st<br>

Get more info here