S
S
smoky-jo2019-09-27 15:39:11
PHP
smoky-jo, 2019-09-27 15:39:11

How to display data in a loop from a database in smarty?

Hello, tell me how to display 30 records from the database in smarty?
let's say I have 100 records in the database, I need to select 30 records in which the category_id=9 column,
I understand that such a query can be made

function minListUsersViwed() {

global $db;
$category_9=$db->fetchRow("select `category_id` from ".TABLE_ADS." where `category_id`=9 ORDER BY `date_added` ASC LIMIT 30");
if(!$category_9) return 0;
return $category_9;
}

then i do this
$category_9 = $listings->minListUsersViwed($category_9);
  $smarty->assign("category_9",$category_9);

and how further in the template to show it in a cycle?
and in my opinion this code above does not work for some reason

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SerJook, 2019-09-27
@SerJook

If it's Smarty 3 then

{foreach $category_9 as $row}
     {$row->column}<br/>
{/foreach}

if smarty 2 then:
{foreach from=$category_9  item=row}
    {$row->column}<br/>
{/foreach}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question