Filter to display output in Excel report with Mysql database and PHP

Asked

Viewed 123 times

0

I can’t create a filter through this query that filters a bank search Mysql with PHP. I started editing it, but the problem is that I can’t generate this method using a variable that’s present on the screen. For example, I did it this way:

$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 am trying to modify to pass a parameter instead of a fixed value (12). I tried so:

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

No results return to me. I’m having difficulty passing this parameter of $empresa. The method was 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');
}
  • "usuarios_id IN (SELECT usuarios_id FROM usuarios WHERE empresas_id = '{$empresa}'" try like this.

  • got thanks

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.