Filter to display result in Excel report with MySQL database and PHP

0

I'm not able to create a filter using this query filtering a search in MySQL with PHP . I started editing it, but the problem is that I can not generate this method using a variable that is present on the screen. For example, I did the following:

$result = $obj->getAll('usuarios_id IN (SELECT usuarios_id FROM usuarios WHERE empresas_id = 12'); 

In this case it works, and displays the results of empresa_id = 12 . I'm trying to modify to pass a parameter instead of fixed value (12). I tried this way:

$result = $obj->getAll('usuarios_id IN (SELECT usuarios_id FROM usuarios WHERE empresas_id = ".$empresa."');

It does not return any results. I'm having difficulty passing this parameter to $empresa . The method looks like this:

public function excelRelatorio() { $arrayRow = array('Nome','Forma Pagamento','Status', 'KM','Valor', 'Valor Extra', 'Data'); $this->geraExcelRelatorio($arrayRow); }

private function geraExcel($arrayRow,$empresa)
{


    $this->load->helper('xls');

    $arr[] = $arrayRow;

    $obj = new Viagem();
    $result = $obj->getAll('usuarios_id IN (SELECT usuarios_id FROM usuarios WHERE empresas_id = ".$empresa."');


    if (isset($result) && count($result) > 0) {

        foreach ($result['rows'] as $v) {

            $arr[] = array(

                utf8_decode($v->getUsuario()->getNome()), $v->getFormaPagamento()->getNome(), $v->getStatus()->getNome(), $v->getDistancia(), $v->getValor(), $v->getValorExtra(), dataHoraBr($v->getDataCriado()), $v->getEntregador()->getNome()

            );

        }

    }

    array_to_xls($arr, 'financeiro'.date("m-d-y").'.xls');
}
    
asked by anonymous 05.12.2017 / 23:01

0 answers