Foros del Web » Programando para Internet » PHP »

Mensaje de registro no existente

Estas en el tema de Mensaje de registro no existente en el foro de PHP en Foros del Web. Hola, Tengo la siguiente página: Código: <?php require_once('Connections/miconexion.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = ...
  #1 (permalink)  
Antiguo 03/12/2008, 09:42
 
Fecha de Ingreso: noviembre-2008
Mensajes: 25
Antigüedad: 15 años, 5 meses
Puntos: 0
Pregunta Mensaje de registro no existente

Hola,

Tengo la siguiente página:

Código:
<?php require_once('Connections/miconexion.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $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;
}
}

mysql_select_db($database_miconexion, $miconexion);
$query_reuniones = "SELECT reuniones.Población, reuniones.Dirección, reuniones.Día, reuniones.Hora, reuniones.Formato, reuniones.Observaciones FROM reuniones WHERE reuniones.Población LIKE '%".trim($_POST['textfield'])."%'";
$reuniones = mysql_query($query_reuniones, $miconexion) or die(mysql_error());
$row_reuniones = mysql_fetch_assoc($reuniones);
$totalRows_reuniones = mysql_num_rows($reuniones);
?><!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=iso-8859-1" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>resultado de reuniones</title>
<!-- TemplateEndEditable -->
<style type="text/css">
<!--
.color {
	background-color: #88D9FF;
}
.style3 {color: #0000FF; font-family: "Courier New", Courier, monospace; }
.style5 {
	color: #0000FF;
	font-family: Georgia, "Times New Roman", Times, serif;
	font-weight: bold;
	font-size: 14px;
}
body {
	background-image: url(logofondoregion.gif);
}
.style6 {font-size: 24px}
.style13 {
	font-size: 14;
	font-family: Georgia, "Times New Roman", Times, serif;
}
.style14 {
	font-size: 16;
	font-family: Georgia, "Times New Roman", Times, serif;
}
.style16 {color: #0000FF}
.style18 {font-family: Georgia, "Times New Roman", Times, serif}
.style19 {background-color: #88D9FF; font-family: Georgia, "Times New Roman", Times, serif; }
.style20 {font-weight: bold; color: #800040;}
.style24 {
	color: #0000FF;
	font-size: 16px;
	font-weight: bold;
}
.style25 {font-size: 16px}
-->
</style>
<!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable -->
</head>

<body>
<p>&nbsp;</p>
<div align="center">
  <h1 align="center" class="style3 style6 style18">Reuniones en <?php echo $_POST['textfield']; ?></h1>
  <p align="center" class="style5 style14 style25">Se encontraron <span class="style16"><?php echo $totalRows_reuniones ?></span> reuniones. </p>
  <table border="1" bordercolor="#88D9FF" bgcolor="#D0EEFB">
    <tr background="logofondoregion.gif">
      <td class="style19"><div align="center" class="style20">Poblaci&oacute;n</div></td>
      <td class="style19"><div align="center" class="style20">Direcci&oacute;n</div></td>
      <td class="style19"><div align="center" class="style20">D&iacute;a</div></td>
      <td class="style19"><div align="center" class="style20">Hora</div></td>
      <td class="style19"><div align="center" class="style20">Formato</div></td>
      <td class="style19"><div align="center" class="style20">Observaciones</div></td>
    </tr>
	<?php $contador = 0; //inicializa el contador fuera del loop ?>
    <?php do { ?>
      <tr <?php if ($contador++ % 2) {echo 'class="color"';}?>>
        <td class="style18"><div align="center" class="style20"><?php echo $row_reuniones['Población']; ?></div></td>
        <td class="style18"><div align="center" class="style20"><?php echo $row_reuniones['Dirección']; ?></div></td>
        <td class="style18"><div align="center" class="style20"><?php echo $row_reuniones['Día']; ?></div></td>
        <td class="style18"><div align="center" class="style20"><?php echo $row_reuniones['Hora']; ?></div></td>
        <td class="style18"><div align="center" class="style20"><?php echo $row_reuniones['Formato']; ?></div></td>
        <td class="style18"><div align="center" class="style20"><?php echo $row_reuniones['Observaciones']; ?></div></td>
      </tr>
      <?php } while ($row_reuniones = mysql_fetch_assoc($reuniones)); ?>
  </table>
  <p align="center"><span class="style18"><a href="index.php"><span class="style24">Nueva b&uacute;squeda</span></a></span></p>
</div>
<a href="index.php">	</a>
</body>
</html>
<?php
mysql_free_result($reuniones);
?>
Me gustaría implementar código para que cuando en el campo de texto el usuario introduzca un registro no existente, en vez de una tabla dinámica vacía como sale ahora, salga un mensaje de texto del tipo "No se encontraron resultados".
¿Me pueden ayudar?
  #2 (permalink)  
Antiguo 03/12/2008, 09:45
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 9 meses
Puntos: 416
Respuesta: Mensaje de registro no existente

Usando mysql_num_rows() y un IF.

http://www.php.net/manual/es/functio...l-num-rows.php
http://www.php.net/manual/en/control-structures.if.php
  #3 (permalink)  
Antiguo 03/12/2008, 09:46
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Respuesta: Mensaje de registro no existente

Hola jozelui,

Usa mysql_num_rows() para eso.

Saludos.
  #4 (permalink)  
Antiguo 03/12/2008, 14:17
 
Fecha de Ingreso: noviembre-2008
Mensajes: 25
Antigüedad: 15 años, 5 meses
Puntos: 0
Respuesta: Mensaje de registro no existente

Gracias a ambos. Yo soy torpe en php. He visto el manual sobre esa funsión y esto es lo que sacado en conclusión:

Código:
$row_reuniones = mysql_fetch_assoc($reuniones);
$totalRows_reuniones = mysql_num_rows($reuniones);
$link = mysql_connect("localhost", "*******", "*****");
mysql_select_db("adictus_reuniones", $link);
$result = mysql_query("SELECT * FROM reuniones", $link);
$num_rows = mysql_num_rows($result);
echo "$No hay reuniones en la población solicitada";
Pués introduciendo este código sale el echo en pantalla pero sigue saliendo la tabla dinámica siempre y la idea es que el mensaje sustituya la tabla dinámica cuando se meta un registro inexistente.
La apertura del tag está más arriba y el tag de cierre vendría al final de ese trozo de código. ¿Podrían ayudarme con el código?
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:30.