Query sweeping all records

0

Good morning, could anyone help me with this return? Well, I have this select:

public function Empenho($id)
{
    $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('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',
                     'cbo.descricao as l', 'emp.folha as m')->get();

    $header = ['Gestora', 'Número', 'Data', 'Hora', 'Valor', 'Credor', 'SubElemento',
        'Despesa', 'Fonte', 'Historico', 'Tipo', 'CBO', 'Folha'];

    return ['Tipo' => 'Empenho', 'header' => $header, 'table' => $table, 'id' => $id];
}

The get method takes all the information, however I'm passing an "id" parameter that gets the ID of each bank record, so I do the mapping and return of the select:

function retornaEmpenho(json){
var result= $('<div>');

for(var i = 0; i < json.header.length; i++)
{
    for(var j = 0; j < json.table.length; j++)
    {
    var arr = $.map(json.table[j], function(value){
        return [value];
    });
}
    var divInner = $('<div>');
    divInner.addClass(json.header[i]);
    divInner.append(json.header[i]+': ');
    divInner.append(arr[i]);
    result.append(divInner);
}       
    return result;
}

Everything is working normally, however I could only do the mapping of the whole record, so my variable "arr" will always receive the last record, since it was the last value assigned, what I wanted to know is, how do I do it? my "arr" variable only map the "$ id" and return only the "$ id" fields, does anyone know how I do it? I'm using laravel. Thank you in advance!

    
asked by anonymous 31.03.2016 / 14:41

1 answer

0

After the line:

$table = DB::table('empenho as emp')

insert your 'where' like this:

->where('nome_da_coluna_de_id', $id)

Try this 'where' and replace 'join (' with 'leftJoin ('.

    
31.03.2016 / 14:59