Tema: Consulta sql
Ver Mensaje Individual
  #2 (permalink)  
Antiguo 31/05/2011, 17:54
Grox
 
Fecha de Ingreso: mayo-2008
Mensajes: 82
Antigüedad: 18 años, 4 meses
Puntos: 3
Respuesta: Consulta sql

Fijate si así te sirve.

Código PHP:
<?php

if(isset($_POST['hijo'])){

$conn= mysql_connect("localhost", "Usuario", "Contraseña");
mysql_select_db("Base de datos", $conn);

$hijo = $_POST['hijo'];
$result = mysql_query("SELECT PARAMNOMCOR FROM tabla WHERE PARAMNOMCOR LIKE '$hijo%'", $conn);
while(
$row = mysql_fetch_array($result, MYSQL_BOTH)){

echo 
$row['PARAMNOMCOR'];
}
}else{
?>
<form method="post">
<input type="text" value="Nombre del Hijo" onclick="this.value=''" name="hijo" size="16">
<input type="submit" value="Buscar Padre">
</form> 
<? } ?>


Y al reves, para buscar hijos del padre:

Código PHP:
<?php

if(isset($_POST['padre'])){

$conn= mysql_connect("localhost", "Usuario", "Contraseña");
mysql_select_db("Base de datos", $conn);

$padre = $_POST['padre'];
$result = mysql_query("SELECT PARAMNOMCOR FROM tabla WHERE PARAMNOMCOR LIKE '%$padre'", $conn);
while(
$row = mysql_fetch_array($result, MYSQL_BOTH)){

echo 
$row['PARAMNOMCOR'];
}
}else{
?>
<form method="post">
<input type="text" value="Nombre del Padre" onclick="this.value=''" name="padre" size="16">
<input type="submit" value="Buscar Hijos">
</form> 
<? } ?>

Última edición por Grox; 31/05/2011 a las 18:16