Foros del Web » Programando para Internet » PHP »

Mensaje de erro

Estas en el tema de Mensaje de erro en el foro de PHP en Foros del Web. Hola¡ puedes ayudar con este codigo, quiero que cuando hago la busqueda si no hay registros en la base de datos me lo diga y ...
  #1 (permalink)  
Antiguo 25/05/2011, 19:11
Avatar de figardi  
Fecha de Ingreso: mayo-2011
Mensajes: 18
Antigüedad: 12 años, 10 meses
Puntos: 0
Pregunta Mensaje de erro

Hola¡ puedes ayudar con este codigo, quiero que cuando hago la busqueda si no hay registros en la base de datos me lo diga y no me ponga una imagen sin nada como me hace ahora, muchas gracias.

<?php require_once('Connections/cocktails.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;
}
}

mysql_select_db($database_cocktails, $cocktails);
$query_busqueda = "SELECT * FROM cockteles ORDER BY nombrecocktail ASC";
$busqueda = mysql_query($query_busqueda, $cocktails) or die(mysql_error());
$row_busqueda = mysql_fetch_assoc($busqueda);
$totalRows_busqueda = mysql_num_rows($busqueda);$colname_busqueda = "-1";
if (isset($_GET['texto'])) {
$colname_busqueda = $_GET['texto'];
}
mysql_select_db($database_cocktails, $cocktails);
$query_busqueda = sprintf("SELECT * FROM cockteles WHERE nombrecocktail like %s ORDER BY nombrecocktail ASC", GetSQLValueString("%" . $colname_busqueda . "%", "text"));
$busqueda = mysql_query($query_busqueda, $cocktails) or die(mysql_error());
$row_busqueda = mysql_fetch_assoc($busqueda);
$totalRows_busqueda = mysql_num_rows($busqueda);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License

Name : Street Clock
Description: A two-column, fixed-width design for 1024x768 screen resolutions.
Version : 1.0
Released : 20110423

-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mascotas</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>

<div id="splash">
<div class="col1"><img src="images/img01.jpg" width="940" height="300" alt="" /></div>
<div class="col2">
<blockquote></blockquote>
</div>
</div>
<div id="header">
<div id="menu">
<ul>
<li class="current_page_item"><a href="index.php" class="first">Homepage</a></li>
<li><a href="noticias.php">Noticias</a></li>
<li><a href="admin.php">Administrador</a></li>
<li><a href="contactar.php">Contactar</a></li>
</ul>
</div>
<!-- end #menu -->
<div id="search">
<form method="get" action="buscar.php">
<fieldset>
<input type="text" name="texto" id="texto" size="30" />
<input type="submit" name="button" id="button" value="Buscar" />
</fieldset>
</form>
</div>
<!-- end #search -->
</div>
<!-- end #header -->
<!-- end #header-wrapper -->
<div id="page"><!-- TemplateBeginEditable name="Contenido" -->
<p>Resultado de la Busqueda:</p>
<table width="73%" align="center">
<tr>
<td colspan="2"><img src="images/linea.png" alt="" width="750" height="3" /></td>
</tr>
<tr>
<td width="35%" rowspan="11" align="left"><img src="<?php echo $row_busqueda['imagencocktail']; ?>" alt="" /></td>
<td width="65%"><?php echo $row_busqueda['nombrecocktail']; ?></td>
</tr>
<tr>
<td><?php echo $row_busqueda['ingre1']; ?></td>
</tr>
<tr>
<td><?php echo $row_busqueda['ingre2']; ?></td>
</tr>
<tr>
<td><?php echo $row_busqueda['ingre3']; ?></td>
</tr>
<tr>
<td><?php echo $row_busqueda['ingre4']; ?></td>
</tr>
<tr>
<td><?php echo $row_busqueda['ingre5']; ?></td>
</tr>
<tr>
<td><?php echo $row_busqueda['ingre6']; ?></td>
</tr>
<tr>
<td><?php echo $row_busqueda['ingre7']; ?></td>
</tr>
<tr>
<td><?php echo $row_busqueda['ingre8']; ?></td>
</tr>
<tr>
<td><?php echo $row_busqueda['ingre9']; ?></td>
</tr>
<tr>
<td><?php echo $row_busqueda['ingre10']; ?></td>
</tr>
<tr>
<td colspan="2"><img src="images/linea2.png" alt="" width="750" height="3" /></td>
</tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<!-- TemplateEndEditable -->
<!-- end #content -->
<!-- end #sidebar -->
<div style="clear: both;">&nbsp;</div>
</div>
<!-- end #page -->
<div id="footer">
<p>Copyright (c) 2011 Figardi</p>
</div>
<!-- end #footer -->
</body>
</html>
<?php
mysql_free_result($busqueda);
?>
  #2 (permalink)  
Antiguo 25/05/2011, 19:25
 
Fecha de Ingreso: julio-2008
Mensajes: 208
Antigüedad: 15 años, 9 meses
Puntos: 5
Respuesta: Mensaje de erro

Antes de imprimir el html pregunta si hay al menos un resultado en la busqueda.

Código:
if ($totalRows_busqueda > 0){
//tu codigo 
}else{
     echo "La busqueda no obtuvo resultados.",
}
Salu2
__________________
Lo maravilloso de aprender algo es que nadie puede arrebatárnoslo.
  #3 (permalink)  
Antiguo 06/06/2011, 12:53
Avatar de figardi  
Fecha de Ingreso: mayo-2011
Mensajes: 18
Antigüedad: 12 años, 10 meses
Puntos: 0
Respuesta: Mensaje de erro

donde podria ponerlo
Gracias
Fidel

esta es la web que espero terminar.

Última edición por GatorV; 07/06/2011 a las 10:41

Etiquetas: mensaje
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 22:27.