Colocar mensaje de "no encontrado" en buscador

Cerrado
dixson_hoepp Mensajes enviados 4 Fecha de inscripción domingo, 2 de marzo de 2014 Estatus Miembro Última intervención miércoles, 5 de marzo de 2014 - 2 mar 2014 a las 18:26
dixson_hoepp Mensajes enviados 4 Fecha de inscripción domingo, 2 de marzo de 2014 Estatus Miembro Última intervención miércoles, 5 de marzo de 2014 - 2 mar 2014 a las 23:00
Buenas a todos, me gustaria que me ayuden, quisiera saber como colocar un mensaje cuando no se encuentre en la base de dato alguna informacion. por ejemplo: "Persona no encontrada"

Aca mi codigo:

<?php require_once('../Connections/registro_estudiantes.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_buscador = "-1";
if (isset($_GET['buscador'])) {
  $colname_buscador = $_GET['buscador'];
}

mysql_select_db($database_registro_estudiantes, $registro_estudiantes);




$query_buscador = sprintf("SELECT * FROM datos_personales WHERE cedula = %s", GetSQLValueString($colname_buscador, "text"));

$buscador = mysql_query($query_buscador, $registro_estudiantes) or die(mysql_error());

$row_buscador = mysql_fetch_assoc($buscador);



$totalRows_buscador = mysql_num_rows($buscador);
	



?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<style type="text/css">
body {
	background-image: url(img/contenido.jpg);
}
.Blanco {
	color: #FFF;
}
.blanco {
	color: #FFF;
	font-weight: bold;
	font-style: italic;
	font-size: 24px;
}
.blanco1 {	color: #FFF;
	font-weight: bold;
	font-style: italic;
	font-size: 24px;
}
.buscar {
	color: #FFF;
}
</style>
<script type="text/javascript">
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
</script>
</head>

<body onload="MM_preloadImages('img/002.gif')">

<a href="contenido.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image1','','img/002.gif',1)"><img src="img/001.gif" alt="inicio" name="Image1" width="54" height="47" id="Image1" /></a>
<form id="form1" name="form1" method="get" action="buscador_alumno.php">
  <table width="315" height="36" border="0" align="center" cellspacing="0">
    <tr>
      <td height="36" colspan="2" align="center"><span class="buscar">Ingresar C.I. del Estudiante</span>
      <input name="buscador" type="text" id="buscador" size="20" />        <input type="submit" name="buscar" id="buscar" value="Buscar" /></td>
    </tr>   
      </table>
  <p> </p>
</form>

<table width="1126" border="0">
  <tr>
    <td width="1503">
    
<table width="1000" height="148" border="1" align="center" cellspacing="0">
  <tr>
    <td height="22" colspan="8" align="center" valign="top" bgcolor="#000000" class="blanco1">DATOS PERSONALES</td>
  </tr>
  <tr>
    <td width="118" height="31" align="center" valign="top">Matricula:</td>
    <td width="128" align="center" valign="top">Nombre:</td>
    <td width="136" align="center" valign="top">Apellido:</td>
    <td width="114" align="center" valign="top">CI:</td>
    <td width="103" align="center" valign="top">Sexo:</td>
    <td width="151" align="center" valign="top">Fecha de Nacimiento:</td>
    <td width="186" align="center" valign="top">Dirección:</td>
    <td width="86" align="center" valign="top">Telefono:</td>
  </tr>
   <?php do { ?>
  <tr>
    <td height="42" align="center" valign="top"><?php echo $row_buscador['ingreso']; ?><?php echo $row_buscador['id']; ?></td>
    <td align="center" valign="top"><?php echo $row_buscador['nombre']; ?></td>
    <td align="center" valign="top"><?php echo $row_buscador['apellido']; ?></td>
    <td align="center" valign="top"><?php echo $row_buscador['cedula']; ?></td>
    <td align="center" valign="top"><?php echo $row_buscador['sexo']; ?></td>
    <td align="center" valign="top"><?php echo $row_buscador['f_nacimiento']; ?></td>
    <td align="center" valign="top"><?php echo $row_buscador['direccion']; ?></td>
    <td align="center" valign="top"><?php echo $row_buscador['tlf']; ?></td>
  </tr>
 
</table>



<p> </p>
<table width="888" height="134" border="1" align="center" cellspacing="0">
  <tr>
    <td height="22" colspan="6" align="center" valign="top" bgcolor="#000000" class="blanco1">REPRESENTANTE DEL ESTUDIANTE</td>
  </tr>
  <tr>
    <td width="171" height="31" align="center" valign="top">Parentesco</td>
    <td width="140" align="center" valign="top">Nombres</td>
    <td width="144" align="center" valign="top">Apellidos</td>
    <td width="151" align="center" valign="top">CI:</td>
    <td width="345" align="center" valign="top">Dirección</td>
    <td width="132" align="center" valign="top">Telefonos:</td>
  </tr>
  
  <tr>
    <td align="center" valign="top"><?php echo $row_buscador['parentesco']; ?></td>
    <td align="center" valign="top"><?php echo $row_buscador['n_repre']; ?></td>
    <td align="center" valign="top"><?php echo $row_buscador['a_repre']; ?></td>
    <td align="center" valign="top"><?php echo $row_buscador['cedula_repre']; ?></td>
    <td align="center" valign="top"><?php echo $row_buscador['direccion_repre']; ?></td>
    <td align="center" valign="top"><?php echo $row_buscador['tlf_repre']; ?></td>
  </tr>
  <?php } while ($row_buscador = mysql_fetch_assoc($buscador));?>
</table>
 
 
    
    
    
    
    
    </td>
  </tr>
</table>

</body>
</html>
          <?php
mysql_free_result($buscador);
?>




2 respuestas

dixson_hoepp Mensajes enviados 4 Fecha de inscripción domingo, 2 de marzo de 2014 Estatus Miembro Última intervención miércoles, 5 de marzo de 2014
Modificado por dixson_hoepp el 2/03/2014, 23:01
Bueno con este codigo:

if ($totalRows_buscador == ""){
  
  echo "No existe";
  
  }
 
 ?> 



logro que aparesca cuando no existe, el problema es que esta estable y solo desaparece cuando se encuentra algo.. Como hago para que solo a paresca cuando le doy buscar y no encuentra nada?
0
dixson_hoepp Mensajes enviados 4 Fecha de inscripción domingo, 2 de marzo de 2014 Estatus Miembro Última intervención miércoles, 5 de marzo de 2014
2 mar 2014 a las 23:00
Problema resuelto:


   <?php
	   
	   
	   
	   if (isset($_GET['buscador'])) {

	   		if ($totalRows_buscador == ""){
	 
	 echo "No existe!!";
	 
	 }
}
	   
 
 ?> 

0