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']);
}