How To Display Rows From MySQL Using PHP And Smarty v2
erics, Posted January 27th, 2012 at 1:58:30pm
The PHP
1 2 3 4 5 6 7 8 9 |
$sql = 'select * from yourTable'; $result = mysql_query($sql); $rows = array(); while ($row = mysql_fetch_assoc($result)) { $rows[] = $row; } $page = new Smarty(); $page->assign('rows', $rows); $page->show('yourTemplate.php'); |
The Smarty Template
1 2 3 4 5 6 7 8 9 10 11 |
{if $rows} {section name=row loop=$rows} {foreach from=$rows[row] key="Key" item="Value"} <p>{$Key}: {$Value}</p> {/foreach} {/section} {else} <h1>NO ROWS FOUND</h1> {/if} |
Leave Your Comment
All fields marked with "*" are required.