Jump to content

Recommended Posts

I have this page:

<?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> </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ón</div></td>
      <td class="style19"><div align="center" class="style20">Dirección</div></td>
      <td class="style19"><div align="center" class="style20">Dí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úsqueda</span></a></span></p>
</div>
<a href="index.php">	</a>
</body>
</html>
<?php
mysql_free_result($reuniones);
?>

 

Í need that when a user of the webpage types a search that is not in the db. The server should return just a message like "no results found", Now appears the dynamic table empty, that should´t appear either.

I've been told that i need to implement it with mysql_num_rows function and If clause. I`ve tried but dont know how to do it. I need someone help me to write it right.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/135490-help-with-mysql_num_rows-function/
Share on other sites

Try this code

 

 

 

<?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> </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ón</div></td>
      <td class="style19"><div align="center" class="style20">Dirección</div></td>
      <td class="style19"><div align="center" class="style20">Dí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 
if ($totalRows_reuniones > 0)
{
	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)); 
}
else
{
?>
	<tr>
		<td colspan="6" class="style18"><div align="center" class="style20">No results found</div></td>

	  </tr>
<?php
}
?>
  </table>
  <p align="center"><span class="style18"><a href="index.php"><span class="style24">Nueva búsqueda</span></a></span></p>
</div>
<a href="index.php">	</a>
</body>
</html>
<?php
mysql_free_result($reuniones);
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.