Código PHP:
<?php
$bus_nombre='\''.$_POST['nombre'].'\'';
$bus_apelpat='\''.$_POST['apellido_pat'].'\'';
$bus_apelmat='\''.$_POST['apellido_mat'].'\'';
if(isset($_POST['buscar']))
{
unset($where);
$and=" AND";
$c=0;
$array = array($bus_nom, $bus_apelpat, $bus_apelmat);
$max=count($array);
for($i=0; $i<$max; $i++){
echo " $array[0]";
if(($_POST[$array[$i]])!=''){
if($c>0)
$union=$and;
else
$union="";
$where.=" $union ".$array[$i]."=".$_POST[$array[$i]]."";
$c++;
}
}
if($c>0)
$where="WHERE $where";
//$query= "SELECT * FROM `cliente_datos` $where ";
//$resultados = mysql_query($query,$db);
$query = 'SELECT * FROM cliente_datos $where ';
$result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
echo " $query " ;
if (mysql_num_rows($result) > 0)
{
echo '<table width=100% cellpadding=0 cellspacing=0 border=1>';
echo
'<tr><td><b>Folio</b></td><td><b>Nombre</b></td><td><b>Apellido Paterno</b></td><td><b>Apellido Materno</b></td><td></tr>';
// iterate over record set
// print each field
while($row = mysql_fetch_row($result))
{
echo '<tr>';
echo '<td>' . $row[0] . '</td>';
echo '<td>' . $row[1] . '</td>';
echo '<td>' . $row[2] . '</td>';
echo '<td>' . $row[3] . '</td>';
echo '</tr>';
}
echo '</table>';
}
}
include "cerrar_conexion.php";
?>