Foros del Web » Programando para Internet » PHP »

consulta PhP para tablas

Estas en el tema de consulta PhP para tablas en el foro de PHP en Foros del Web. Estimados, queria pedir ayuda con esto... necesito hacer una busqueda que se ordene en una tabla, me explico, tengo este codigo el cual me busca ...
  #1 (permalink)  
Antiguo 24/10/2012, 14:29
 
Fecha de Ingreso: octubre-2012
Mensajes: 1
Antigüedad: 11 años, 5 meses
Puntos: 0
consulta PhP para tablas

Estimados, queria pedir ayuda con esto...
necesito hacer una busqueda que se ordene en una tabla, me explico, tengo este codigo el cual me busca todos los datos que necesito

Cita:
$query = mysql_query("SELECT medicos.nombre, medicos.apellido, semana.semana, turno.dia, turno.hra, lugar.lugar, medicos.tipo, medicos.especialidad FROM medicos ,semana ,turno ,lugar ,horario WHERE medicos.id_med = horario.id_med AND semana.id_semana = horario.id_semana AND
turno.id_turno = horario.id_turno AND lugar.id_lugar = horario.id_lugar");


print '<table>
<tr>
<th>Nombre</th>
<th>Lugar</th>
<th>dia</th>
<th>Hora</th>
</tr>';
while ($row = mysql_fetch_assoc($query)){
print '<tr>
<td>'.$row['nombre'].' '.$row['apellido'].'</td>
<td>'.$row['lugar'].'</td>
<td>'.$row['dia'].'</td>
<td>'.$row['hra'].'</td>
</tr>';
}
print '</table>';
Resultado:
Código HTML:
<table>
<tr>
  		<th >Nombre</th>
		<th >Lugar</th>
		<th>Dia</th>
		<th>Horario</th>
		</tr>
<tr>
  		<th >Hernan</th>
		<th >Sala 4</th>
		<th> Lunes</th>
		<th>8:30-10:30</th>
		</tr>
 <tr>
  		<th >Hernan</th>
		<th >Sala 1</th>
		<th> Lunes</th>
		<th>10:30-13:30</th>
		</tr>                    
        <tr>
  		<th >Dr Farias</th>
		<th >Licencia</th>
		<th> Viernes</th>
		<th>13:30-17:00</th>
		</tr> 
                      <tr>
  		<th >Soledad</th>
		<th >Sala 3  </th>
		<th> Lunes</th>
		<th>13:30-17:00</th>
		</tr> 
</table> 
ahora necesito que la busqueda se separe en tablas que contega un horario especifico, que cuando arroje todos los datos se separen segun dia y hora, ejemplo:
Cita:
<table>
<tr>
<th >Nombre</th>
<th >8:30-10:30</th>
<th>10:30-13:30</th>
<th>13:30-17:00</th>
</tr>
Dia "Lunes"
|Nombre | 8:30-10:30 | 10:30-13:30 | 13:30-17:00 |
|Hernan | Sala 4 | Sala 1 |
Soledad | - -- ----- | ----------- | Sala 3

Dia "Viernes"
|Nombre |8:30-10:30 |10:30-13:30 | 13:30-17:00
|Dr Farias | ---------- | ------------- | Licencia

ojala se entienda. Gracias
  #2 (permalink)  
Antiguo 25/10/2012, 15:47
Avatar de Marvin
Colaborador
 
Fecha de Ingreso: febrero-2005
Ubicación: global $Chile->Santiago;
Mensajes: 1.991
Antigüedad: 19 años, 2 meses
Puntos: 81
Respuesta: consulta PhP para tablas

Me tinca que si asocias los datos a una hora, podria funcionar:
Código PHP:
Ver original
  1. while ($row = mysql_fetch_assoc($query)){
  2.     $arrTotal[$row['dia']][$row['hra']]['nombre'][] = $row['nombre'].' '.$row['apellido'];
  3.     $arrTotal[$row['dia']][$row['hra']]['lugar'][]  = $row['lugar'];
  4. }
Asi despues puedes recorrer los resultados que van a quedar de esta manera:
Código PHP:
Ver original
  1. $arrTotal['Lunes']['8:30-10:00']['nombre'][0] //'Juan Perez'
  2. $arrTotal['Lunes']['8:30-10:00']['lugar'][0] // 'Sala 1';
  3. $arrTotal['Lunes']['8:30-10:00']['nombre'][1] //'Eduardo Flores'
  4. $arrTotal['Lunes']['8:30-10:00']['lugar'][1] // 'Sala 2';
  5. $arrTotal['Lunes']['8:30-10:00']['nombre'][2] //'Emilio Rodriguez'
  6. $arrTotal['Lunes']['8:30-10:00']['lugar'][2] // 'Sala 1';
Saludos!
__________________
El que dice "Solo sé que nada sé", esta asumiendo que sabe algo.
Lea las FAQ's!

Etiquetas: mysql, tabla, tablas
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 06:27.