Ver Mensaje Individual
  #4 (permalink)  
Antiguo 04/01/2015, 13:46
Miguel9801
 
Fecha de Ingreso: enero-2015
Ubicación: Bogota
Mensajes: 10
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Consultar y mostrar un dato específico

Yo lo haría así!

Código HTML:
<html> 
<body> 
<form method="POST" action="buscar.php"> 
<strong>Cedula:</strong> <input type="text" name="ced" size="20"><br><br> 
<input type="submit" value="Buscar" name="buscar"> 
</form> 
</body> 
</html> 
en el archivo buscar.php
Código PHP:
<html> 
<body> 
  
<?php 
if (!isset($buscar)){ 
      echo 
"Debe especificar una cadena a bucar"; 
      echo 
"</html></body> \n"; 
      exit; 
} 
$link = mysql_connect("localhost", "nobody"); 
mysql_select_db("mydb", $link); 
$result = mysql_query("SELECT * FROM personal WHERE cedula '%$buscar%' ORDER BY nombre", $link); 
if (
$row = mysql_fetch_array($result)){ 
      echo 
"<table border = '1'> \n"; 
//Mostramos los nombres de las tablas 
echo "<tr> \n"; 
while (
$field = mysql_fetch_field($result)){ 
            echo 
"<td>$field->name</td> \n"; 
} 
      echo 
"</tr> \n"; 
do { 
echo 
"Cedula:" . $reg['cedula'] . "<br>"; 
echo 
"Apellidos:" . $reg['apellidos'] . "<br>";
echo 
"Nombres:" . $reg['nombre'] . "<br>";
echo 
"Puesto" . $reg['puesto'] . "<br>";
echo 
"Sueldo" . $reg['sueldo'] . "<br>"; </a></td> n"; 
            echo "
</tr> n"; 
      } while ($row = mysql_fetch_array($result)); 
            echo "
</table> n"; 
} else { 
echo "
¡ No se ha encontrado ningún registro !"; 
} 
?> 
  
</body> 
</html>