Concatenate variable php

0

I want to concatenate a variable, that is, as in the example below, the variable expenses is increased to the number. An example would be: expenses1, expenses2, expenses3, etc until the while ends.

$i=0;
        while ($listado=$c11->fetch(PDO::FETCH_ASSOC)){
        $i++;
            $gastos="SELECT ncuenta,dcuenta,SUM(saldo) as monto2,fiscal FROM ".nombre1." WHERE SUBSTR(NCUENTA,1,1)='6' and fiscal='".$f."' and fecha>='".$fechaini."'and fecha<='".$fechafin."' and cod_subempresa=".$listado['id_proyecto']." and cod_subsub=".$listado['id_subproyecto']." and factura<>'CIERRES' GROUP BY substr(NCUENTA,1,7) ORDER BY cod_subempresa,cod_subsub,NCUENTA";
            $gastos.strval($i)=$dbh->prepare($gastos);
            $gastos.strval($i)->execute(); 
            print_r($list['id_proyecto']);
        }
    
asked by Oscar Melendez 04.09.2018 в 22:07
source

1 answer

0

The complete solution to the doubt I had before is the following:

            $gastos="SELECT ncuenta,dcuenta,SUM(saldo) as monto2,fiscal FROM ".nombre1." WHERE SUBSTR(NCUENTA,1,1)='6' and fiscal='".$f."' and fecha>='".$fechaini."'and fecha<='".$fechafin."' and cod_subempresa=0 and cod_subsub=0 and factura<>'CIERRES' GROUP BY substr(NCUENTA,1,7) ORDER BY NCUENTA";
        $gastos0=$dbh->prepare($gastos);
        $gastos0->execute(); 

        $i=0;
        while ($listado=$c11->fetch(PDO::FETCH_ASSOC)){
            $i++;
            $gasto[$i]=0;
            ${"nombre".$i}=$listado['proyecto'];
            $gastos="SELECT ncuenta,dcuenta,SUM(saldo) as monto2,fiscal FROM ".nombre1." WHERE SUBSTR(NCUENTA,1,1)='6' and fiscal='".$f."' and fecha>='".$fechaini."'and fecha<='".$fechafin."' and cod_subempresa=".$listado['id_proyecto']." and cod_subsub=".$listado['id_subproyecto']." and factura<>'CIERRES' GROUP BY substr(NCUENTA,1,7) ORDER BY cod_subempresa,cod_subsub,NCUENTA";
            ${"gastos".$i}=$dbh->prepare($gastos);
            ${"gastos".$i}->execute(); 
            while ($datos=${"gastos".$i}->fetch(PDO::FETCH_ASSOC)){
            $gasto[$i]=$datos;
            array_push($gasto[$i], ${"nombre".$i});
            print_r($gasto[$i]);
            }
        }

the code I use to make a report of financial statements detailed by project and that's why I used it in an array to call it later

    
answered by 04.09.2018 / 22:26
source