Foros del Web » Programando para Internet » PHP »

control de flujo

Estas en el tema de control de flujo en el foro de PHP en Foros del Web. Tengo una tabla con nobres de empleados y otra con horarios de trabajo. Intento poner en la tabla de horarios el nombre de los empleados ...
  #1 (permalink)  
Antiguo 13/06/2012, 11:40
 
Fecha de Ingreso: enero-2008
Mensajes: 303
Antigüedad: 16 años, 2 meses
Puntos: 0
control de flujo

Tengo una tabla con nobres de empleados y otra con horarios de trabajo.

Intento poner en la tabla de horarios el nombre de los empleados con:

Código PHP:
$quer1 "SELECT turnoscreados.id, personal.nombre FROM turnoscreados left JOIN personal ON personal.rota =0 ";
$temp2 mysql_query($quer1$barco) or die(mysql_error()); 
while (
$row2 mysql_fetch_row($temp2)){
  
$update="update turnoscreados set turno='$row2[1]' where id='$row2[0]'";$x++;echo $update;
 } 
Pero el ciclo se repite (id x nombes) veces.
Código HTML:
update turnoscreados set turno='Jorge Enrique Rincón Peña' where id='111'update turnoscreados set turno='Carlos Bonal' where id='111'update turnoscreados set turno='Guillermo Molina Hernandez' where id='111'update turnoscreados set turno='Maria Angeles Limañana García' where id='111'update turnoscreados set turno='Giovanny Baltan Diaz' where id='111'update turnoscreados set turno='Antonio García Irles' where id='111'update turnoscreados set turno='Juan Carlos Blanco García' where id='111'update turnoscreados set turno='Isabel García Martín' where id='111'update turnoscreados set turno='Francisco Javier Tornero Luna' where id='111'update turnoscreados set turno='Omar Haddadov' where id='111'update turnoscreados set turno='Mustapha Achalhi' where id='111'update turnoscreados set turno='Raul Arnoldo Diaz' where id='111'update turnoscreados set turno='Nasku' where id='111'update turnoscreados set turno='Jorge Enrique Rincón Peña' where id='112'update turnoscreados set turno='Carlos Bonal' where id='112'update turnoscreados set turno='Guillermo Molina Hernandez' where id='112'update turnoscreados set turno='Maria Angeles Limañana García' where id='112'update turnoscreados set turno='Giovanny Baltan Diaz' where id='112'update turnoscreados set turno='Antonio García Irles' where id='112'update turnoscreados set turno='Juan Carlos Blanco García' where id='112'update turnoscreados set turno='Isabel García Martín' where id='112'update turnoscreados set turno='Francisco Javier Tornero Luna' where id='112'update turnoscreados set turno='Omar Haddadov' where id='112'update turnoscreados set turno='Mustapha Achalhi' where id='112'update turnoscreados set turno='Raul Arnoldo Diaz' where id='112'update turnoscreados set turno='Nasku' where id='112'update turnoscreados set turno='Jorge Enrique Rincón Peña' where id='113'update turnoscreados set turno='Carlos Bonal' where id='113'update turnoscreados set turno='Guillermo Molina Hernandez' where id='113'update turnoscreados set turno='Maria Angeles Limañana García' where id='113'update turnoscreados set turno='Giovanny Baltan Diaz' where id='113'update turnoscreados set turno='Antonio García Irles' where id='113'update turnoscreados set turno='Juan Carlos Blanco García' where id='113'update turnoscreados set turno='Isabel García Martín' where id='113'update turnoscreados set turno='Francisco Javier Tornero Luna' where id='113'update turnoscreados set turno='Omar Haddadov' where id='113'update turnoscreados set turno='Mustapha Achalhi' where id='113'update turnoscreados set turno='Raul Arnoldo Diaz' where id='113'update turnoscreados set turno='Nasku' where id='113'update turnoscreados set turno='Jorge Enrique Rincón Peña' where id='114'update turnoscreados set turno='Carlos Bonal' where id='114'update turnoscreados set turno='Guillermo Molina Hernandez' where id='114'update turnoscreados set turno='Maria Angeles Limañana García' where id='114'update turnoscreados set turno='Giovanny Baltan Diaz' where id='114'update turnoscreados set turno='Antonio García Irles' where id='114'update turnoscreados set turno='Juan Carlos Blanco García' where id='114'update turnoscreados set turno='Isabel García Martín' where id='114'update turnoscreados set turno='Francisco Javier Tornero Luna' where id='114'update turnoscreados set turno='Omar Haddadov' where id='114'update turnoscreados set turno='Mustapha Achalhi' where id='114'update turnoscreados set turno='Raul Arnoldo Diaz' where id='114'update turnoscreados set turno='Nasku' where id='114'update turnoscreados set turno='Jorge Enrique Rincón Peña' where id='115'update turnoscreados set turno='Carlos Bonal' where id='115'update turnoscreados set turno='Guillermo Molina Hernandez' where id='115'update turnoscreados set turno='Maria Angeles Limañana García' where id='115'update turnoscreados set turno='Giovanny Baltan Diaz' where id='115'update turnoscreados set turno='Antonio García Irles' where id='115'update turnoscreados set turno='Juan Carlos Blanco García' where id='115'update turnoscreados set turno='Isabel García Martín' where id='115'update turnoscreados set turno='Francisco Javier Tornero Luna' where id='115'update turnoscreados set turno='Omar Haddadov' where id='115'update turnoscreados set turno='Mustapha Achalhi' where id='115'update turnoscreados set turno='Raul Arnoldo Diaz' where id='115'update turnoscreados set turno='Nasku' where id='115'update turnoscreados set turno='Jorge Enrique Rincón Peña' where id='116'update turnoscreados set turno='Carlos Bonal' where id='116'update turnoscreados set turno='Guillermo Molina Hernandez' where id='116'update turnoscreados set turno='Maria Angeles Limañana García' where id='116'update turnoscreados set turno='Giovanny Baltan Diaz' where id='116'update turnoscreados set turno='Antonio García Irles' where id='116'update turnoscreados set turno='Juan Carlos Blanco García' where id='116'update turnoscreados set turno='Isabel García Martín' where id='116'update turnoscreados set turno='Francisco Javier Tornero Luna' where id='116'update turnoscreados set turno='Omar Haddadov' where id='116'update turnoscreados set turno='Mustapha Achalhi' where id='116'update turnoscreados set turno='Raul Arnoldo Diaz' where id='116'update turnoscreados set turno='Nasku' where id='116'update turnoscreados set turno='Jorge Enrique Rincón Peña' where id='117'update turnoscreados set turno='Carlos Bonal' where id='117'update turnoscreados set turno='Guillermo Molina Hernandez' where id='117'update turnoscreados set turno='Maria Angeles Limañana García' where id='117'update turnoscreados set turno='Giovanny Baltan Diaz' where id='117'update turnoscreados set turno='Antonio García Irles' where id='117'update turnoscreados set turno='Juan Carlos Blanco García' where id='117'update turnoscreados set turno='Isabel García Martín' where id='117'update turnoscreados set turno='Francisco Javier Tornero Luna' where id='117'update turnoscreados set turno='Omar Haddadov' where id='117'update turnoscreados set turno='Mustapha Achalhi' where id='117'update turnoscreados set turno='Raul Arnoldo Diaz' where id='117'update turnoscreados set turno='Nasku' where id='117'update turnoscreados set turno='Jorge Enrique Rincón Peña' where id='118'update turnoscreados set turno='Carlos Bonal' where id='118'update turnoscreados set turno='Guillermo Molina Hernandez' where id='118'update turnoscreados set turno='Maria Angeles Limañana García' where id='118'update turnoscreados set turno='Giovanny Baltan Diaz' where id='118'update turnoscreados set turno='Antonio García Irles' where id='118'update turnoscreados set turno='Juan Carlos Blanco García' where id='118'update turnoscreados set turno='Isabel García Martín' where id='118'update turnoscreados set turno='Francisco Javier Tornero Luna' where id='118'update turnoscreados set turno='Omar Haddadov' where id='118'update turnoscreados set turno='Mustapha Achalhi' where id='118'update turnoscreados set turno='Raul Arnoldo Diaz' where id='118'update turnoscreados set turno='Nasku' where id='118'update turnoscreados set turno='Jorge Enrique Rincón Peña' where id='119'update turnoscreados set turno='Carlos Bonal' where id='119'update turnoscreados set turno='Guillermo Molina Hernandez' where id='119'update turnoscreados set turno='Maria Angeles Limañana García' where id='119'update turnoscreados set turno='Giovanny Baltan Diaz' where id='119'update turnoscreados set turno='Antonio García Irles' where id='119'update turnoscreados set turno='Juan Carlos Blanco García' where id='119'update turnoscreados set turno='Isabel García Martín' where id='119'update turnoscreados set turno='Francisco Javier Tornero Luna' where id='119'update turnoscreados set turno='Omar Haddadov' where id='119'update turnoscreados set turno='Mustapha Achalhi' where id='119'update turnoscreados set turno='Raul Arnoldo Diaz' where id='119'update turnoscreados set turno='Nasku' where id='119'update turnoscreados set turno='Jorge Enrique Rincón Peña' where id='120'update turnoscreados set turno='Carlos Bonal' where id='120'update turnoscreados set turno='Guillermo Molina Hernandez' where id='120'update turnoscreados set turno='Maria Angeles Limañana García' where id='120'update turnoscreados set turno='Giovanny Baltan Diaz' where id='120'update turnoscreados set turno='Antonio García Irles' where id='120'update turnoscreados set turno='Juan Carlos Blanco García' where id='120'update turnoscreados set turno='Isabel García Martín' where id='120'update turnoscreados set turno='Francisco Javier Tornero Luna' where id='120'update turnoscreados set turno='Omar Haddadov' where id='120'update turnoscreados set turno='Mustapha Achalhi' where id='120'update turnoscreados set turno='Raul Arnoldo Diaz' where id='120'update turnoscreados set turno='Nasku' where id='120'
como puedo hacer esto?
  #2 (permalink)  
Antiguo 13/06/2012, 12:06
Avatar de patriciomase  
Fecha de Ingreso: abril-2012
Ubicación: Mar del Plata
Mensajes: 323
Antigüedad: 12 años
Puntos: 34
Respuesta: control de flujo

control de flujo??

y cual es el problema? hace el update adentro del while y listo..

Igualmente no entiendo tu codigo, ese left join está raro "ON personal.rota =0", en el on tenés que definir los campos que van a vincular las tablas
  #3 (permalink)  
Antiguo 13/06/2012, 12:18
Avatar de carlos_belisario
Colaborador
 
Fecha de Ingreso: abril-2010
Ubicación: Venezuela Maracay Aragua
Mensajes: 3.156
Antigüedad: 14 años
Puntos: 461
Respuesta: control de flujo

tu duda no esta clara, además que no tienes un buen diseño en la base de datos, no deberías de repetir los nombre de los empleados en otra tabla que no sea la que tiene los datos personales de los mismos, para eso están las claves, saludos
__________________
aprende d tus errores e incrementa tu conocimientos
it's not a bug, it's an undocumented feature By @David
php the right way
  #4 (permalink)  
Antiguo 13/06/2012, 12:19
Avatar de fjrueda  
Fecha de Ingreso: marzo-2008
Ubicación: Bucaramanga
Mensajes: 313
Antigüedad: 16 años, 1 mes
Puntos: 35
Respuesta: control de flujo

Eurodoblon.

Claro que se repite, porque usted colocando el update del "While" y esa "$x++" esta sobrando porque al parecer no la esta usando en ningun otro lado.

Que es lo realmente esta tratando de hacer ??
  #5 (permalink)  
Antiguo 13/06/2012, 12:25
Avatar de fjrueda  
Fecha de Ingreso: marzo-2008
Ubicación: Bucaramanga
Mensajes: 313
Antigüedad: 16 años, 1 mes
Puntos: 35
Respuesta: control de flujo

Eurodoblon.

Claro que se repite, porque usted colocando el update del "While" y esa "$x++" esta sobrando porque al parecer no la esta usando en ningun otro lado.

Que es lo realmente esta tratando de hacer ??
  #6 (permalink)  
Antiguo 13/06/2012, 12:46
 
Fecha de Ingreso: enero-2008
Mensajes: 303
Antigüedad: 16 años, 2 meses
Puntos: 0
Respuesta: control de flujo

Perdonad $x++ sobra.
ON lo uso como condicion, podría ser Where, es para que me seleccione los que quiero.

En cuanto a lo que dice Carlos , no entiendo muy bien porque no puedo traer datos de una tabla donde tengo el nombre de los empleados a otra donde tengo turnos y quiero asignarle uno.

Perdonad que os complique con mi ignorancia
Gracias y un saludo
  #7 (permalink)  
Antiguo 13/06/2012, 18:25
Avatar de fjrueda  
Fecha de Ingreso: marzo-2008
Ubicación: Bucaramanga
Mensajes: 313
Antigüedad: 16 años, 1 mes
Puntos: 35
Respuesta: control de flujo

Pues no es necesario con el id deveria ser suficiente, pero igual es su diseño y usted lo utiliza como quiere.

Como al parecer solo nesecita actualizar un campo y utilise un un "WHERE" en la select, es mas seguro.

Hagale y responda para ver como le fue.
  #8 (permalink)  
Antiguo 14/06/2012, 01:30
 
Fecha de Ingreso: enero-2008
Mensajes: 303
Antigüedad: 16 años, 2 meses
Puntos: 0
Respuesta: control de flujo

Muchas gracias a todos,
Cada día me gusta más este foro por la gran colaboración que hay.

Por eso me gusta dejar al final de cada hilo la solución si es que la consigo:

Seguramente habrá algo más simple, pero he optado por limitar la busqueda a un solo registro con el fín de que el ciclo NO se repita tantas veces obligado por while:

Código PHP:
$consulta "SELECT id FROM `turnoscreados` WHERE `turno` LIKE '%TURNO%' ";
$consult mysql_query($consulta$barco) or die(mysql_error()); 
 
$numero mysql_num_rows($consult);
       
for(
$f=0$f<=$numero$f++){       
    
$quer "SELECT id, turno FROM `turnoscreados` WHERE `turno` LIKE '%TURNO%' LIMIT 0, 1 ";
$temp mysql_query($quer$barco) or die(mysql_error()); 
while (
$row mysql_fetch_assoc($temp)){         
$query "SELECT nombre FROM personal where rota=1 LIMIT $f ,1";
$temp2 mysql_query($query$barco) or die(mysql_error()); 
while (
$row2 mysql_fetch_assoc($temp2)){

mysql_query("update turnoscreados set turno='$row2[nombre]' where id='$row[id]'");
 
}
}

  #9 (permalink)  
Antiguo 14/06/2012, 08:12
Avatar de carlos_belisario
Colaborador
 
Fecha de Ingreso: abril-2010
Ubicación: Venezuela Maracay Aragua
Mensajes: 3.156
Antigüedad: 14 años
Puntos: 461
Respuesta: control de flujo

Sigo diciendo que tu diseño de base de datos esta mal y te hago una serie de preguntas a ver si vez el porque o si yo entiendo el porque de la forma como lo haces, donde esta la relación entre el personal y el turno??, porque redundas datos (nombre de la tabla personal a otra vez nombre en la tabla turnoscreados) en otra tabla cuando debería haber una relación entre un campo clave y una fk, ahora imagina que en vez de escribir carlos belisario por error de dedos escribiste calros velizario y ya hiciste la actualización y quieres acomodarme el nombre tendrías que hacerlo cuantas veces?? Lo primero que debes de hacer antes de lanzarte a echar el código de la aplicación es un buen diseño del software tu sistema y un buen diseño de la base de datos ahí es donde radica el exito de tu sistema, sino cuando vaya creciendo se va a volver inmantenible, saludos, espero que mi comentario te oriente
__________________
aprende d tus errores e incrementa tu conocimientos
it's not a bug, it's an undocumented feature By @David
php the right way

Etiquetas: control, flujo, mysql, sql, tabla
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:25.