$from_date AND utimestamp < $to_date AND id_agente_modulo = $id_agentmodule ORDER BY utimestamp DESC"; } else { $sql1 = " SELECT * FROM tagente_datos WHERE utimestamp > $from_date AND utimestamp < $to_date AND id_agente_modulo = $id_agentmodule ORDER BY utimestamp DESC"; } $result1 = db_get_all_rows_sql($sql1, true); if ($result1 === false) { $result1 = []; } // Render data foreach ($result1 as $row) { echo $agentmodule_name; echo ','; echo $row['datos']; echo ','; echo $row['utimestamp']; echo chr(13); } }