V
V
viktorross2019-12-17 11:33:17
PHP
viktorross, 2019-12-17 11:33:17

Why are the values ​​not displayed in the template in the loop?

hello, please tell me why I am not displaying values ​​from the database to the template?

function getCategories_M() {
$get_cat = $db->fetchRow("select * from `classes_categories_lang`");

while($row = $db->fetchAssoc($get_cat))
{
    $id = $row['id'];
    $name = $row['name'];

}
}

$c = new categories();
$get_cat = $c->getCategories_M();
$smarty->assign("get_cat", $get_cat);

{foreach from=$rows item=rowItem}          
{$rowItem.id}
{$rowItem.name}
{/foreach}

please tell me how to make it work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FanatPHP, 2019-12-17
@FanatPHP

Because you wrote nonsense code just by adding a few lines of code at random?
First, you have to forget about templates, smarts and output. And ask how to get an array from the database.
And only having received your array, begin to deal with its output.
Secondly, you must answer yourself a few questions.
What does the line $get_cat = $db->fetchRow("select * from `classes_categories_lang`") do, why is it needed here and what does it return.
What does the line while($row = $db->fetchAssoc($get_cat)) do, why is it needed here and what does it return.
Well, the most interesting thing is what the lines $id = $row['id']; do. and $name = $row['name'];.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question