Here's my PHP code (A query which returns rows having 2 columns: ReportId and MailingFrequency):
while($x=mysql_fetch_assoc($result1))
{
$X[0] = $x['ReportId'];
$X[1] = $x['MailingFrequency'];
$X[2] = 'Stop Subscription';
$this->smarty->assign("X", $X);
}
My HTML code (To display data from smarty variable X):
{section name=index loop = $X}
<tr>
<td width="25%">{$X[0]}</td>
<td width="35%">{$X[1]}</td>
<td width="40%"><a href="../webadmin/stopsubscription" id="StopSubscription" style="color: #CC0000">{$X[2]}</a></td>
</tr>
Now, in the case dataset has only one row of format (ReportId,MailingFrequency) e.g.(1,'Saturday'), it is displayed correctly. But, in case of multiple rows, only the last row is displayed. How to display all the rows in the html table?
In your code X value was constantly overwritten:
$list = array();
while($x=mysql_fetch_assoc($result1))
{
$list[] = array(
'report_id' => $x['ReportId'],
'mailing frequency' => $x['MailingFrequency'],
'text' => 'Stop Subscription'
);
}
$this->smarty->assign(compact('list'));
View:
{foreach from=list item=val}
<tr>
<td width="25%">{$val.report_id}</td>
<td width="35%">{$val.mailing_frequency}</td>
<td width="40%"><a href="../webadmin/stopsubscription" id="StopSubscription" style="color: #CC0000">{$val.text}</a></td>
</tr>
{/foreach}