1
Good evening, could someone please help me with this: I made a select and gave a "get()" at the end to get the results, I passed them in an array I’m picking up a Function via ajax:
$table = DB::table('empenho as emp')
->join('gestora', 'emp.unidGestId', '=', 'gestora.id')
->join('gestora_tipo', 'gestora.tipoId', '=', 'gestora_tipo.id')
->join('despesa', 'emp.fichaOrcId', '=', 'despesa.id')
->join('pessoa', 'emp.fornecedorId', '=', 'pessoa.id')
->join('sub_elemento', 'emp.subElementoId', '=', 'sub_elemento.id')
->join('fonte', 'emp.fonteId', '=', 'fonte.id')
->join('siops', 'emp.siopsId', '=', 'siops.id')
->join('cbo', 'emp.cboId', '=', 'cbo.id')
->select('gestora_tipo.nome as a', 'emp.nrEmpenho as b', 'emp.date as c', 'emp.hora_insc as d',
'emp.valor as e', 'pessoa.nome as f', 'sub_elemento.codSubElem as g', 'despesa.valor as h',
'fonte.descricao as i', 'emp.historico as j', 'emp.tipo as k', 'siops.descricao as l',
'cbo.descricao as m', 'emp.folha as n')->get();
$header = ['Gestora', 'Número', 'Data', 'Hora', 'Valor', 'Credor', 'SubElemento',
'Despesa', 'Fonte', 'Historico', 'Tipo', 'Siops', 'CBO', 'Folha'];
return ['Tipo' => 'Empenho', 'header' => $header, 'table' => $table, 'id' => $id];
However I’m not being able to show the result containing the fields filled with the values of the database, when I do a go in ajax it even takes the $header variable, but it doesn’t take the $table, I can’t make this return work, someone could tell me what I’m missing?
function retornaEmpenho(json){
var result= $('<div>');
for(var i = 0; i < json.header.length; i++)
{
var divInner = $('<div>');
divInner.addClass(json.header[i]);
divInner.append(json.header[i]+': '+json.table[i]);
result.append(divInner);
}
When I do it by throwing the fields in with the values, the header works(of course), but the $table does not return me the right one, only a value "Undefined", someone help me please ! Grateful from now on.
Colleague try to make a print_r of $table and do a for with php (foreach $table as $t echo $t->a) to print the data if it works adjust its function in ajax.
– Evert
My $table is not returning anything to me, totally empty, it seems that the problem is in it, but I can’t understand why of it nor where I’m going wrong.
– Lincoln Binda
Put the select before Join, test with a table and add the joins.
– Evert