Database query within a Smarty template

0

Is it possible to query my BD within a template Smarty ? I already have the variable available that will enable my query, but the tests I did, I did not, I already did a file that does the search and makes the template call, but also did not work, because it accuses the syntax error, which I did was this:


$pk0 =  $_REQUEST['pk0'];

$res = mysql_query("SELECT * FROM cadCotas WHERE IdCota = '".$pk0."' "); 
$num_linhas = mysql_numrows($res);
for($i = 0; $i assign("Data", $array_Data); 
$smarty->assign("Hora", $array_Hora); 
$smarty->assign("IdUnicoopOrigem", $array_IdUnicoopOrigem); 
$smarty->assign("IdLocalDescarga", $array_IdLocalDescarga); 
$smarty->assign("IdProduto", $array_IdProduto); 
$smarty->display("iPrintAutorizacao.tpl"); 

The error you are giving is this:

Fatal error: Smarty error: [in custom_templates/BuscaDadosCotas.php line 8]: syntax error: unrecognized tag: $array_Data[] = mysql_result($res, $i, "Data"); $array_Hora[] = mysql_result($res, $i, "Hora"); $array_IdUnicoopOrigem[] = mysql_result($res, $i, "IdUnicoopOrigem"); $array_IdLocalDescarga[] = mysql_result($res, $i, "IdLocalDescarga"); $array_IdProduto[] = mysql_result($res, $i, "IdProduto"); (Smarty_Compiler.class.php, line 442) in /home/dir/public_html/transporte/libs/smartylibs/Smarty.class.php on line 1093

The template I already have and would like to query directly from it is this:

<div style="width: 100%; float: left; margin-bottom: 1em;">
<table width="100%" border="1" style="font-size: 1.3em;">
    <tbody>
        <tr>
            <td width="46%" align="center"><img src="" width="233"  alt=""/></td>
            <td width="27%" align="center"><h2>Autorização de Carga </h2></td>
            <td width="27%" align="center"><h2>Nº {$Grid.Row.IdAutorizacao.DisplayValue}</h2></td>
            </tr>
        <tr>
            <td height="24" align="left"><strong>Cota Nº:</strong> {$Grid.Row.IdCota.DisplayValue}</td>
            <td colspan="2" align="left"><strong>Unidade:</strong> {$Grid.Row.IdUnicoopOrigem.DisplayValue}</td>
        </tr>
        <tr>
            <td height="24" colspan="3" align="left"><strong>Data da Cota:</strong> {if $Grid.Row.Data.Value != NULL}  {$Grid.Row.Data.Value|date_format:"%d/%m/%Y"} {else} {/if} <strong>Hora:</strong> {if $Grid.Row.Hora.Value != NULL}  {$Grid.Row.Hora.DisplayValue} {else} {/if}</td>
            </tr>
        <tr>
            <td height="24" colspan="3" align="left"><strong>Cota Nº:</strong> {$Grid.Row.IdCota.DisplayValue}</td>
            </tr>
        <tr>
            <td height="24" colspan="3" align="left"><strong>Transportadora:</strong> {$Grid.Row.IdPessoa.DisplayValue}</td>
            </tr>
        <tr>
            <td height="21" colspan="3" align="left"><strong>Classificador:</strong> {$Grid.Row.IdClassificadora.DisplayValue}</td>
        </tr>
        <tr>
            <td height="21" colspan="3" align="left"><strong>Produto:</strong> {$Grid.Row.IdProduto.DisplayValue}</td>
        </tr>
        <tr>
            <td height="21" colspan="3" align="left"><strong>Veículo: </strong>{$Grid.Row.IdVeiculo.DisplayValue}</td>
            </tr>
        <tr>
            <td height="24" align="left"><strong>Origem: </strong>{$Grid.Row.IdUnicoopOrigem.DisplayValue}</td>
            <td colspan="2" align="left"><strong>Destino: </strong>{$Grid.Row.IdLocalDescarga .DisplayValue}</td>
        </tr>
        <tr>
            <td height="24" align="left"><strong>Data Autorização:</strong>{if $Grid.Row.DataAutorizacao.Value != NULL}  {$Grid.Row.DataAutorizacao.Value|date_format:"%d/%m/%Y"} {else} {/if} <strong>Hora:</strong> {if $Grid.Row.HoraAutorizacao.Value != NULL}  {$Grid.Row.HoraAutorizacao.DisplayValue} {else} {/if}</td>
            <td colspan="2" align="left"><p><strong>Data Triagem:</strong>{if $Grid.Row.DataTriagem.Value != NULL}  {$Grid.Row.DataTriagem.Value|date_format:"%d/%m/%Y"} {else} {/if} <strong>Hora:</strong> {if $Grid.Row.HoraTriagem.Value != NULL}  {$Grid.Row.HoraTriagem.DisplayValue} {else} {/if}</p></td>
            </tr>
        <tr>
            <td height="21" align="left"><strong>Data Entrada:</strong>{if $Grid.Row.DataEntrada.Value != NULL}  {$Grid.Row.DataEntrada.Value|date_format:"%d/%m/%Y"} {else} {/if} <strong>Hora</strong>: {if $Grid.Row.HoraEntrada.Value != NULL}  {$Grid.Row.HoraEntrada.DisplayValue} {else} {/if}</td>
            <td height="21" colspan="2" align="left"><strong>Data Carregamento: </strong>{if $Grid.Row.DataCarregamento.Value != NULL}  {$Grid.Row.DataCarregamento.Value|date_format:"%d/%m/%Y"} {else} {/if} <strong>Hora</strong>: {if $Grid.Row.HoraCarregamento.Value != NULL}  {$Grid.Row.HoraCarregamento.DisplayValue} {else} {/if}</td>
            </tr>
        <tr>
            <td height="21" align="left">&nbsp;</td>
            <td height="21" colspan="2" align="left">&nbsp;</td>
        </tr>
         
        {if $Grid.Row.Observacao.Value != NULL}       
        {/if}
        <tr>
            <td height="21" colspan="3" align="center" bgcolor="#ECECEC"><strong>Nota Fiscal</strong></td>
        </tr>
        <tr>
            <td height="21" align="center">Número</td>
            <td height="21" colspan="2" align="center">Data</td>
        </tr>
        <tr>
            <td height="21" align="center">{if $Grid.Row.NF.Value != NULL}  {$Grid.Row.NF.DisplayValue} {else}Sem NF cadastrada{/if}</td>
            <td height="21" colspan="2" align="center">&nbsp;</td>
        </tr>    
</table>
</div>
    
asked by anonymous 01.08.2018 / 14:09

0 answers