Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/08/2016, 13:52
VR1387
 
Fecha de Ingreso: abril-2016
Mensajes: 19
Antigüedad: 8 años
Puntos: 0
Recorrer un array de una sentencia sql

Buenas tardes a todos.

Tengo este codigo, como prueba que estoy haciendo.

Código:
<html>
<head>
<title>Busqueda de  clientes</title>
</head>
<body>
<center>
<form action="buscarclientes.php" method="post">
<table border="2" bordercolor="#151515" bgcolor="#F7F8E0" width="600">
	<tr>
		<td width="150"><center>Cedula o Nombre</center>
		</td>
		<td>
    	<input type="text" maxlength="9" size="5"  name="cedula">
    	<input type="submit" name="buscar" value="Buscar">
		</td>
	</tr>
</table>
</form>
		<input type="submit" name="regresar" value="Regresar al inicio" onclick="location='index.php'">
</center>
<?php
require "conexion.php";

if (isset($_POST['cedula'])) {
$ced=$_POST['cedula'];
$queryconsulta=mysql_query("SELECT nombre, apellido, hora, fecha FROM tb_trab
							INNER JOIN tb_eventos on tb_trab.cedula = tb_eventos.cedula
							where tb_trab.cedula='$ced'",$con);



$mostrar='
<center>
<table border="2" bordercolor="#151515" bgcolor="#F7F8E0" width="600">
	<tbody>
		<tr>
			<td>Nombre</td>
			<td>Apellido</td>
			<td>Hora</td>
			<td>Fecha</td>
		</tr>
		<tr>
<center>';
foreach($array=mysql_fetch_array($queryconsulta) as $arreglo){
	echo $arreglo;
}
	while($array=mysql_fetch_array($queryconsulta)){
	$nombre="$array[nombre]";
	$apellido="$array[apellido]";
	$hora="$array[hora]";
	$fecha="$array[fecha]";
		echo $mostrararray='
		<center>
		<table>
		<tr>
			<td><input type="text"  disabled size="" value="'.$nombre.'"></td>
			<td><input type="text"  disabled size="" value="'.$apellido.'"></td>
			<td><input type="text"  disabled size="" value="'.$hora.'"></td>
			<td><input type="text"  disabled size="" value="'.$fecha.'"></td>
		</tr>
		</tbody>
		</table>
		</center>';
	} // while

}
else
	echo "<center>Debe introducir una cedula</center>";

?>
</body>
</html>
El la sentencia de SQL se realiza a la perfeccion y me muestra los datos que quiero.

Lo que quiero optimizar en este caso es como puedo recorrer el array de una manera mas simple, se que existe el foreach que me llama mucho la atencion, pero no logro aun como recorrer ese array desde la sentencia sql.


Saludos