By: decastro
Date: 2013-08-02
Time: 18:14
|
SubBlock
Hello, I'm trying to make a subblock work but I guess I'm doing something wrong.
Please have a look at my code:
$sql = $db->sql_query("SELECT * FROM categorias WHERE id_empresa = " . $_SESSION['sessao_id_empresa'] . " AND id_parent = 0 ORDER BY id DESC");
$total = $db->sql_numrows($sql);
if ($total != 0)
{
while ($linha = $db->sql_fetchrow($sql))
{
$categorias[] = array('nome' => $linha['nome'],'id' => $linha['id']);
$sql2 = $db->sql_query("SELECT * FROM subcategorias WHERE id_empresa = " . $_SESSION['sessao_id_empresa'] . " AND id_parent = 0 AND id_categoria = " . $linha['id']);
echo $total2 = $db->sql_numrows($sql2);
if ($total2 != 0)
{
while ($linha2 = $db->sql_fetchrow($sql2))
{
$subcategorias[] = array('nome' => $linha2['nome'], 'id' => $linha2['id']);
}
}
}
$tpl->MergeBlock('categorias', $categorias);
$tpl->MergeBlock('subcategorias', $subcategorias);
$tpl->Render;
$tpl->Show();
<tr>
<td>[categorias.nome;block=tr] <p>[subcategorias.nome;block=p;p1=[categorias.id]]</p></td>
<td class="center"><a href="editar.php?idioma=pt&id=[categorias.id]"><img src="/img/flags/pt_PT.gif"></a> |
<a href="editar.php?idioma=en&id=[categorias.id]"><img src="/img/flags/en_GB.gif"></a> | <a href="editar.php?idioma=fr&id=[categorias.id]"><img src="/img/flags/fr_FR.gif"></a> | <a href="editar.php?idioma=de&id=[categorias.id]"><img src="/img/flags/de_DE.gif"></a> | <a href="editar.php?idioma=es&id=[categorias.id]"><img src="/img/flags/es_ES.gif"></a></td>
<td class="center">
<!--<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
Ver
</a>-->
<a class="btn btn-danger" href="categorias/apagar.php?id=[categorias.id]">
<i class="icon-trash icon-white"></i>
Apagar
</a>
<a class="btn btn-info" href="subcategorias/adicionar.php?id=[categorias.id]">
<i class="icon-edit icon-white"></i>
Adicionar Sub-categoria
</a>
</td>
</tr>
Can you show me what's wrong with it?
Thanks
|
By: Skrol29
Date: 2013-08-21
Time: 00:35
|
Re: SubBlock
Hi decastro,
The problem is that you did not define the link between $categorias and $subcategorias at the PHP side.
Replace :
$subcategorias[] = array('nome' => $linha2['nome'], 'id' => $linha2['id']); |
with :
$subcategorias[ $linha2['id'] ] = array('nome' => $linha2['nome'], 'id' => $linha2['id']); |
And replace :
$tpl->MergeBlock('subcategorias', $subcategorias); |
with :
global $subcategorias;
$tpl->MergeBlock('subcategorias', 'array', 'subcategorias[%p1%]');
|
|