hookit Posted December 4, 2008 Share Posted December 4, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/135490-help-with-mysql_num_rows-function/ Share on other sites More sharing options...
PravinS Posted December 4, 2008 Share Posted December 4, 2008 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/135490-help-with-mysql_num_rows-function/#findComment-705838 Share on other sites More sharing options...
hookit Posted December 4, 2008 Author Share Posted December 4, 2008 Thanks so much PBS. Now is almost solved, the message appears when is typed a search not found in db. But still appears inside the dynamic table, table shouldn´t appear, only message. Any suggestion? Quote Link to comment https://forums.phpfreaks.com/topic/135490-help-with-mysql_num_rows-function/#findComment-705958 Share on other sites More sharing options...
.josh Posted December 4, 2008 Share Posted December 4, 2008 $sql = "select column from table where column=$x"; $result = mysql_query($sql); if (mysql_num_rows($result) > 0) { // put while loop that makes table here } else { // echo no results message } Quote Link to comment https://forums.phpfreaks.com/topic/135490-help-with-mysql_num_rows-function/#findComment-705961 Share on other sites More sharing options...
hookit Posted December 4, 2008 Author Share Posted December 4, 2008 Will be so kind anyone of doing the script as suggested by Mr. Violent? I will be very grateful. i have to admit that i do not know how to do it. Quote Link to comment https://forums.phpfreaks.com/topic/135490-help-with-mysql_num_rows-function/#findComment-706009 Share on other sites More sharing options...
.josh Posted December 4, 2008 Share Posted December 4, 2008 We aren't here to write your script for you. People get paid for that sort of thing. Quote Link to comment https://forums.phpfreaks.com/topic/135490-help-with-mysql_num_rows-function/#findComment-706020 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.