Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP smarty database output

How to output all rows in a database with smarty ?

like image 332
weardstuff Avatar asked Apr 22 '26 17:04

weardstuff


1 Answers

Basically, read the database data in a "controller" or something like that and send them to smarty using a variable, much like this:

$db = GetSomeDbObject();

$rows = $db->Query("Select * From aTable");
$smarty->assign("rows", $rows);
$smarty->display("index.tpl");

And, now in a smarty file (index.tpl)

<h2>Smarty Rows</h2>
{foreach $rows as $row}
  Row Name: {$row.FieldName}
{/foreach}
like image 82
David Conde Avatar answered Apr 24 '26 06:04

David Conde