0
Still beginner in Nodejs and working with Express, Handlebars and Mysql.
In a form - which in the future will be a register, this has among other inputs, two <select>
any, one must be filled with data from one table (Requester) and the other <select>
with data from a second table().
In the same call to the route app.get
(express), there is the possibility to render the result of two queries to the bank?
Since the call is unique and automatically sending headers res.send()
/res.render()
is only allowed once also.
Remark: In trying to get around this with SQL, used union
in the composition of select
, but it doesn’t help, because Handlebars has no conditions at the level of:
{{#if tabela}}
{{#each tabela.campo = "valor"}}
{{/each}}
{{/if}}
Nor something similar, so that one can popular each <select>
separately
I don’t think this is important, in this case, but dry the codes, both from the call, and from the excerpt HTML coded Handlebars.
Note: The code brings back the data, of which only one <select>
. I know that the union
is not the solution.
Excerpt Nodejs:
app.get('/cad', function(req,res){
cnx.query(' SELECT id_acadsol, st_nome_acadsol, "ACAD" as ret from tbl_academia_solicitante '+
' union all '+
' SELECT id_func,st_nome_func,"FUNC" as ret FROM TBL_FUNCIONARIO',function(error,results){
console.log(results);
if(error){
result = console.log('Erro ao obter solicitantes e responsáveis. ' + error.message);
}
res.render('cadsolicitacao',{
"tbl_academia_solicitante": results
});
})
});
Excerpt Handlebars:
<td>
{{#if tbl_academia_solicitante}}
<select class="browser-default custom-select" id="sel_academia_solicitante">
<option selected>Selecione o solicitante</option>
{{#each tbl_academia_solicitante}}
<option value={{id_acadsol}}>{{st_nome_acadsol}}</option>
{{/each}}
</select>
{{else}}
Nenhum resultado para a consulta (solicitante)
{{/if}}
</td>