Answer the question
In order to leave comments, you need to log in
How to output a loop in smarty?
hello, please tell me an example of outputting a loop in smart along with a php request to the database.
I searched the Internet almost everything does not work and an error occurs.
I just need a query to a row in the database, for example, the ads table and the name column for this column, there are several thousand records, I want to display all of them in one array in the template in a loop, no matter how much I tried, nothing happens, maybe someone saw a 100% working example or knows
Answer the question
In order to leave comments, you need to log in
Smarty does not provide database queries; it's basically none of his business. He needs to serve a ready-made array and iterate over it in a loop - for example, foreach.
<?php
$arr = array(1000, 1001, 1002);
$smarty->assign('myArray', $arr);
?>
<ul>
{foreach from=$myArray item=foo}
<li>{$foo}</li>
{/foreach}
</ul>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question