function getDateLast() { $registro; $date = $_GET["hoy"]; for ($i = 0; $i <= 7; $i++) { $query = "SELECT `ID`,`FECHA`,`HORA`,`TOTAL_FUEL`,`TOTAL_HRS` FROM `" . nombreTabla() . "` WHERE fecha="; if ($i == 1) { $str = " -" . $i . " day"; } else { $str = " -" . $i . " days"; } //echo $str."\n"; $fecha_reciente = date('Y-m-d', strtotime($date . $str)); //echo date('Y-m-d', strtotime($date.$str))."\n"; $query = $query . "'" . $fecha_reciente . "' ORDER BY id DESC LIMIT 1"; $result = dbQuery($query); $json_array = array(); if (!$result) { $error = dbError(); echo $error; } else { while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)) { array_push($json_array, $row); $registro = $row; } //echo str_replace(array('[',']'),"",json_encode($json_array,JSON_UNESCAPED_UNICODE)); if ($json_array != null) { break; } //else //echo "No hay registros para esta fecha\n"; } } return $registro; }
function dbError() { $conexion = dbConnect(); return mysqli_error($conexion); } //Ejecución de consultas function dbQuery($query) { $conexion = dbConnect(); $result = mysqli_query($conexion, $query); return $result; } //Insercion de datos if ($tipo == "short") { $query = "SELECT `FECHA`,`HORA`,`COD_ALARM` FROM `" . nombreTabla() . "` ORDER BY id DESC LIMIT 1"; } else { $query = "SELECT * FROM `" . nombreTabla() . "` LEFT JOIN `MTU_ALARMAS` ON " . nombreTabla() . ".COD_ALARM=MTU_ALARMAS.Codigo ORDER BY id DESC LIMIT 1"; } //$query = "SELECT * FROM `".nombreTabla()."` ORDER BY id DESC LIMIT 1"; //$query = "SELECT * FROM `MTU_ALARMAS` WHERE `Codigo`='23'"; $result = dbQuery($query); $json_array = array(); if (!$result) { $error = dbError(); echo $error; } else { while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)) { array_push($json_array, $row); } echo str_replace(array('[', ']'), "", json_encode($json_array, JSON_UNESCAPED_UNICODE)); }
} return $conexion; } function nombreTabla() { $config = parse_ini_file("dbparam.ini"); $table_name = $config['tablename']; return $table_name; } // Error Handler function dbError() { $conexion = dbConnect(); return mysqli_error($conexion); } //Ejecución de consultas function dbQuery($query) { $conexion = dbConnect(); $result = mysqli_query($conexion, $query); return $result; } //Insercion de datos $query = "INSERT INTO `" . nombreTabla() . "` (`ID`, `FECHA`, `HORA`, `RPM_ACTUAL`, `OIL_PRESS`, `OIL_TEMP`, `COOL_LEVEL`, `COOL_TEMP`,`COD_ALARM`,`TOTAL_FUEL`,`TOTAL_HRS`, `2_RPM_ACTUAL`, `2_OIL_PRESS`, `2_OIL_TEMP`, `2_COOL_LEVEL`, `2_COOL_TEMP`,`2_COD_ALARM`,`2_TOTAL_FUEL`,`2_TOTAL_HRS`) VALUES (ABS(NULL), '" . $fecha . "', '" . $hora . "', '" . $rpm . "', '" . $oilpress . "', '" . $oiltemp . "', '" . $coollevel . "', '" . $cooltemp . "', '" . $codigo . "', '" . $fuel . "', '" . $hrs . "', '" . $rpm2 . "', '" . $oilpress2 . "', '" . $oiltemp2 . "', '" . $coollevel2 . "', '" . $cooltemp2 . "', '" . $codigo2 . "', '" . $fuel2 . "', '" . $hrs2 . "')"; $result = dbQuery($query); if (!$result) { $error = dbError(); echo $error; } else { echo "Data succesfully uploaded to database."; }