Respuesta: repetir un registro en base a una fecha delimitada. no, no me explique bien, paso a aexpicar con lujo de detalles, me encuentro relaizando un sistema de venta de pasajes, y resulta que una ves creeadas las planillas de horarios para los buses, existen muchas de estas que se repetin durante lagunos dias e incluso se mantienen durante semanas es por eso la nececidad de crear una periocidad, para estas que significa INSERTAR NUEVAMENTE LOS REGISTROS de las planillas ya creadas, pero modificando acorde a las nuevas fechas., la periocidad diaria es facil ya que son dias de corrido, pero la periocidad semanal no lo es, ya que aca existen algunas limitantes, por ejemplo repetir una planilla durante 4 semanas, pero solo de lunes a jueves, o repetir esta palnilla por 4 semanas pero solo lpos viernes o solo los sabados, pondre el codigo completo para ves si me pueden ayudar. Código PHP: $flag = $_POST['bandera'];//ESTE ES UN MARCADOR if ($flag == "diaria"){ //HAGO LA PERIOCIDAD DIARIA SIMILAR A LA SEMANAL ACA ABAJO SOLO SUMO UN DIA EN VES DE UNA SEMANA }//cierre if2 else{ $indice3 = $_POST['semanas']; $f_mov = date('Y-m-d',strtotime ($_POST['fecha_inicio'])); for ($indice = 1; $indice <= $indice3; $indice++){ $horario = $_POST['horario']; $hr_time = explode(":", $horario); $insertSQL = sprintf("INSERT INTO planillas (origen_c, ori, id_origen, destino_c, des, id_destino, horario, hr_hr, hr_min, hrdescripcion, fecha, id_ruta, desc_ruta, unidad_zn, tipo_serv, configuracion, status, cadena, dominio, n_asientos, bano) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['origen_c'], "text"), GetSQLValueString($_POST['ori'], "text"), GetSQLValueString($_POST['id_origen'], "text"), GetSQLValueString($_POST['destino_c'], "text"), GetSQLValueString($_POST['des'], "text"), GetSQLValueString($_POST['id_destino'], "text"), GetSQLValueString($_POST['horario'], "text"), GetSQLValueString($hr_time[0], "text"), GetSQLValueString($hr_time[1], "text"), GetSQLValueString($_POST['hrdescripcion'], "text"), GetSQLValueString($f_mov, "date"), GetSQLValueString($_POST['id_ruta'], "int"), GetSQLValueString($_POST['desc_ruta'], "text"), GetSQLValueString($_POST['unidad_zn'], "text"), GetSQLValueString($_POST['tipo_serv'], "text"), GetSQLValueString($_POST['configuracion'], "text"), GetSQLValueString($_POST['status'], "text"), GetSQLValueString($_POST['cadena'], "int"), GetSQLValueString($_POST['dominio'], "text"), GetSQLValueString($_POST['n_asientos'], "int"), GetSQLValueString($_POST['bano'], "text")); mysql_select_db($database_lfox3, $lfox3); $Result1 = mysql_query($insertSQL, $lfox3) or die(mysql_error()); //rescato el idnum insertado $colname_rs1= mysql_insert_id(); //actualizo el campo cadena $updateSQL = sprintf("UPDATE planillas SET cadena=%s WHERE idnum=%s", GetSQLValueString($colname_rs1, "int"), GetSQLValueString($colname_rs1, "int")); mysql_select_db($database_lfox3, $lfox3); $Result2 = mysql_query($updateSQL, $lfox3) or die(mysql_error()); //rescato los intermedios de la ruta $id_ruta = $_POST['id_ruta']; mysql_select_db($database_SFox3, $SFox3); $query_rs4 = sprintf("select fox3.rutas_det.id_ruta, fox3.rutas_det.cod_of, fox3.rutas_det.agencia, fox3.rutas_det.agencia_c, fox3.distancias.ciudad, fox3.distancias.km, fox3.distancias.tiempo_hr, fox3.distancias.tiempo_min from fox3.rutas_det, fox3.distancias where ((fox3.rutas_det.cod_of = fox3.distancias.cod_of2) and (fox3.rutas_det.cod_origen = fox3.distancias.cod_of1) and (fox3.rutas_det.id_ruta = %s)) order by fox3.distancias.km asc", $id_ruta); $rs4 = mysql_query($query_rs4, $SFox3) or die(mysql_error()); $row_rs4 = mysql_fetch_assoc($rs4); $totalRows_rs4 = mysql_num_rows($rs4); //while ($row_rs4 = mysql_fetch_assoc($rs4)){ // gererar ciclo de insert do { //Asigna datos de planillas intermedias $iorigen = $row_rs4['agencia']; $iorigen_c = $row_rs4['agencia_c']; $iorigen_id = $row_rs4['cod_of']; $thrs_p2 = $row_rs4['tiempo_hr']; $tmin_p2 = $row_rs4['tiempo_min']; $hora_inter = $thrs_p2.":".$tmin_p2; //tratamiento de fecha y hora para las planillas intermedias // Convertimos fecha y hora en timestamps // Creamos la fecha inicial con su hora correspondiente $fecha = $f_mov; $hora_ini = $horario; $hora_ter = $hora_inter; $inicial = strtotime("$fecha $hora_ini");
// Obtenemos hora y minutos en base a la hora final hh:mm list($hr,$min) = explode(':', $hora_ter); // Convertimos la hora final en segundos $agregar = ($hr * 3600) + ($min * 60); // Obtenemos la fecha final agregando las horas transcurridas // de esta forma, la fecha tambien se actualiza $fecha_final = $inicial + $agregar; // Ahora puedes obtener la fecha y hora final list($dia, $mes, $anio, $hr, $min) = explode('-', date('d-m-Y-H-i', $fecha_final)); $hora_final = "$hr:$min"; $fecha_f = "$anio-$mes-$dia"; //insert $insertSQL = sprintf("INSERT INTO planillas (origen_c, ori, id_origen, destino_c, des, id_destino, horario, hr_hr, hr_min, hrdescripcion, fecha, id_ruta, desc_ruta, unidad_zn, tipo_serv, configuracion, status, cadena, dominio, n_asientos, bano) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($iorigen, "text"), GetSQLValueString($iorigen_c, "text"), GetSQLValueString($iorigen_id , "text"), GetSQLValueString($_POST['destino_c'], "text"), GetSQLValueString($_POST['des'], "text"), GetSQLValueString($_POST['id_destino'], "text"), GetSQLValueString($hora_final, "text"), GetSQLValueString($hr, "text"), GetSQLValueString($min, "text"), GetSQLValueString($_POST['hrdescripcion'], "text"), GetSQLValueString($fecha_f , "date"), GetSQLValueString($_POST['id_ruta'], "int"), GetSQLValueString($_POST['desc_ruta'], "text"), GetSQLValueString($_POST['unidad_zn'], "text"), GetSQLValueString($_POST['tipo_serv'], "text"), GetSQLValueString($_POST['configuracion'], "text"), GetSQLValueString($_POST['status'], "text"), GetSQLValueString($colname_rs1, "int"), GetSQLValueString($_POST['dominio'], "text"), GetSQLValueString($_POST['n_asientos'], "int"), GetSQLValueString($_POST['bano'], "text")); mysql_select_db($database_lfox3, $lfox3); $Result1 = mysql_query($insertSQL, $lfox3) or die(mysql_error()); } while ($row_rs4 = mysql_fetch_assoc($rs4)); $mañana = strtotime("+".$indice." week",strtotime($_POST['fecha_inicio']));//ACA DEBERIA IR LA DE LAS SEMANAS $f_mov = date('Y-m-d',$mañana); }//cierre for $insertGoTo = "planillas.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } }//cierre if1 //Periocidad semanal $colname_rs1 = "1"; if (isset($_GET['key'])) { $colname_rs1 = (get_magic_quotes_gpc()) ? $_GET['key'] : addslashes($_GET['key']); } mysql_select_db($database_lfox3, $lfox3); $query_rs1 = sprintf("SELECT * FROM planillas WHERE idnum = %s", $colname_rs1); $rs1 = mysql_query($query_rs1, $lfox3) or die(mysql_error()); $row_rs1 = mysql_fetch_assoc($rs1); $totalRows_rs1 = mysql_num_rows($rs1); $dominio = $_GET['kdominio'];
Última edición por jetzona; 26/01/2009 a las 08:29
Razón: FALTA SIGNO
|