Foros del Web » Programando para Internet » PHP »

Consulta, arrays php en tablas html

Estas en el tema de Consulta, arrays php en tablas html en el foro de PHP en Foros del Web. Hola amigos, me gustaria hacerles la siguiente consulta, tengo el siguiente array en php, escribo la tabla en html, pero tengo problemas al representar el ...
  #1 (permalink)  
Antiguo 16/10/2012, 20:42
 
Fecha de Ingreso: octubre-2012
Mensajes: 1
Antigüedad: 11 años, 6 meses
Puntos: 0
Pregunta Consulta, arrays php en tablas html

Hola amigos, me gustaria hacerles la siguiente consulta, tengo el siguiente array en php, escribo la tabla en html, pero tengo problemas al representar el indice del array osea la cabecera, me gustaria que solo saliera una fila, y no todas las demas, pienso que es un problema con el recorrido del array

<?php
$agenda=array(array('fecha'=>'12-03-12','h_inicio'=>'09:40am','h_fin'=>'10:30am','acti vidad'=>'clase'),
array('fecha'=>'13-03-12','h_inicio'=>'10:40a','h_fin'=>'11:30am','activ idad'=>'jugar'),
array('fecha'=>'14-03-12','h_inicio'=>'08:40am','h_fin'=>'9:30am','activ idad'=>'clase'),
array('fecha'=>'15-03-12','h_inicio'=>'06:40am','h_fin'=>'8:30am','activ idad'=>'hablar por tel'),
array('fecha'=>'16-03-12','h_inicio'=>'11:40am','h_fin'=>'12:30am','acti vidad'=>'clase'));

?>

<!doctype html>
<html>
<head>
<title> renderizado con echo </title>
</head>
<body>

<table align="center" border= "1" width="500">
<thead>

<tr>
<th bgcolor="yellow" colspan="4">agenda</th>
</tr>

<?php
foreach($agenda as $indice=> $valor){
echo "<tr>\n";
foreach($valor as $ind1=>$val1){
echo'<td>'.$ind1.'</td>';
}
'</tr>';
}

?>

</thead>

<?php
foreach($agenda as $indice=> $valor){
echo "<tr>\n";
foreach($valor as $ind1=>$val1){
echo'<td>'.$val1.'</td>';
}
'</tr>';
}

?>


</table>
</body>
</html>

Ese codigo va a mostrar la tabla, pero adiciona todas las filas del indice del recorrido en la tabla, yo solo quiero uno
  #2 (permalink)  
Antiguo 16/10/2012, 23:04
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: Consulta, arrays php en tablas html

Si sólo quieres un elemento, no recorras todo el arreglo, omite el primer foreach y en el segundo usas $agenda['indice_que_quieres'] en lugar de $valor.
__________________
- León, Guanajuato
- GV-Foto

Etiquetas: tablass
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 17:53.