hookit Posted December 1, 2008 Share Posted December 1, 2008 Hi, I have been given this php snippet: $Res = mysql_query($chainSQL); if(mysql_num_rows($Res)>0){ #If results found show list while($otmp = mysql_fetch_object($Res)){} }else{ echo 'NO RESULTS FOUND; } In this script i must introduce the dynamic´s table code in order to get the echo output if the condition is met. Here is where i been told to write the table´s code: if(mysql_num_rows($Res)>0){ //Here introduce tablè's code } Well, my doubt comes to how embed this code into because i wrote it as this but the code remains in black text not changing into colors when the php setence is right: <table border="1" align="center" bordercolor="#88D9FF" bgcolor="#D0EEFB"> <tr background="images/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> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/135029-help-how-to-draft-correctly-a-php-snippet/ Share on other sites More sharing options...
ScotDiddle Posted December 1, 2008 Share Posted December 1, 2008 hookit You're missing a closing quote here: echo 'NO RESULTS FOUND; Scot L. Diddle, Richmond VA Quote Link to comment https://forums.phpfreaks.com/topic/135029-help-how-to-draft-correctly-a-php-snippet/#findComment-703295 Share on other sites More sharing options...
hookit Posted December 1, 2008 Author Share Posted December 1, 2008 That has been done but the else clause part of the script remains black, it has to be something else. Any suggestion? Quote Link to comment https://forums.phpfreaks.com/topic/135029-help-how-to-draft-correctly-a-php-snippet/#findComment-703408 Share on other sites More sharing options...
Maq Posted December 1, 2008 Share Posted December 1, 2008 //for error reporting, if no errors delete this... ini_set ("display_errors", "1"); error_reporting(E_ALL); $Res = mysql_query($chainSQL); if(mysql_num_rows($Res)>0){ </pre> <table border="1" align="center" bordercolor="#88D9FF" bgcolor="#D0EEFB"> Población Dirección Día Hora Formato Observaciones while($otmp = mysql_fetch_object($Res)){ ?> > </table> <br> echo 'NO RESULTS FOUND';<br>} Quote Link to comment https://forums.phpfreaks.com/topic/135029-help-how-to-draft-correctly-a-php-snippet/#findComment-703415 Share on other sites More sharing options...
hookit Posted December 2, 2008 Author Share Posted December 2, 2008 Thanks Maq: if i apply your script the server reports this error log: Parse error: syntax error, unexpected '<' in /home/whatever/domains/whatever.com/public_html/results.php on line 45 [<table border="1" align="center" bordercolor="#88D9FF" bgcolor="#D0EEFB">/code] It seems that there is something wrong with '<' Thanks Quote Link to comment https://forums.phpfreaks.com/topic/135029-help-how-to-draft-correctly-a-php-snippet/#findComment-703815 Share on other sites More sharing options...
waynew Posted December 2, 2008 Share Posted December 2, 2008 <?php //for error reporting, if no errors delete this... ini_set ("display_errors", "1"); error_reporting(E_ALL); $Res = mysql_query($chainSQL); if(mysql_num_rows($Res)>0){ ?> <table border="1" align="center" bordercolor="#88D9FF" bgcolor="#D0EEFB"> <tr background="images/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 while($otmp = mysql_fetch_object($Res)){ ?> <tr <?php if ($contador++ % 2) {echo 'class="color"';}?>> <td class="style18"><div align="center" class="style20"><?php echo $otmp['Población']; ?></div></td> <td class="style18"><div align="center" class="style20"><?php echo $otmp['Dirección']; ?></div></td> <td class="style18"><div align="center" class="style20"><?php echo $otmp['Día']; ?></div></td> <td class="style18"><div align="center" class="style20"><?php echo $otmp['Hora']; ?></div></td> <td class="style18"><div align="center" class="style20"><?php echo $otmp['Formato']; ?></div></td> <td class="style18"><div align="center" class="style20"><?php echo $otmp['Observaciones']; ?></div></td> </tr> <?php } ?> </table> <?php } else{ echo 'NO RESULTS FOUND'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/135029-help-how-to-draft-correctly-a-php-snippet/#findComment-703822 Share on other sites More sharing options...
Maq Posted December 2, 2008 Share Posted December 2, 2008 Parse error: syntax error, unexpected ' It's because I forgot to close the PHP tag. Thanks wayne Quote Link to comment https://forums.phpfreaks.com/topic/135029-help-how-to-draft-correctly-a-php-snippet/#findComment-703918 Share on other sites More sharing options...
hookit Posted December 2, 2008 Author Share Posted December 2, 2008 If i paste the last code posted by wayne remains with same error as before but in the first line of this snippet: <?php //for error reporting, if no errors delete this... ini_set ("display_errors", "1"); error_reporting(E_ALL); I can´t make it work. Quote Link to comment https://forums.phpfreaks.com/topic/135029-help-how-to-draft-correctly-a-php-snippet/#findComment-704235 Share on other sites More sharing options...
Maq Posted December 2, 2008 Share Posted December 2, 2008 Please post the exact error and the current code you're using. Quote Link to comment https://forums.phpfreaks.com/topic/135029-help-how-to-draft-correctly-a-php-snippet/#findComment-704238 Share on other sites More sharing options...
hookit Posted December 2, 2008 Author Share Posted December 2, 2008 Error log: Parse error: syntax error, unexpected '<' in /****/a9807048/public_html/resultados.php on line 38 This is qhere line 38 begins: <?php //for error reporting, if no errors delete this... ini_set ("display_errors", "1"); error_reporting(E_ALL); His is the whole script: <?php //for error reporting, if no errors delete this... ini_set ("display_errors", "1"); error_reporting(E_ALL); $Res = mysql_query($chainSQL); if(mysql_num_rows($Res)>0){ ?> <table border="1" align="center" bordercolor="#88D9FF" bgcolor="#D0EEFB"> <tr background="images/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 while($otmp = mysql_fetch_object($Res)){ ?> <tr <?php if ($contador++ % 2) {echo 'class="color"';}?>> <td class="style18"><div align="center" class="style20"><?php echo $otmp['Población']; ?></div></td> <td class="style18"><div align="center" class="style20"><?php echo $otmp['Dirección']; ?></div></td> <td class="style18"><div align="center" class="style20"><?php echo $otmp['Día']; ?></div></td> <td class="style18"><div align="center" class="style20"><?php echo $otmp['Hora']; ?></div></td> <td class="style18"><div align="center" class="style20"><?php echo $otmp['Formato']; ?></div></td> <td class="style18"><div align="center" class="style20"><?php echo $otmp['Observaciones']; ?></div></td> </tr> <?php } ?> </table> <?php } else{ echo 'NO RESULTS FOUND'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/135029-help-how-to-draft-correctly-a-php-snippet/#findComment-704351 Share on other sites More sharing options...
DeanWhitehouse Posted December 2, 2008 Share Posted December 2, 2008 Show all the code, if what you say is line 38 then you haven't posted all the code Quote Link to comment https://forums.phpfreaks.com/topic/135029-help-how-to-draft-correctly-a-php-snippet/#findComment-704356 Share on other sites More sharing options...
hookit Posted December 3, 2008 Author Share Posted December 3, 2008 This is the code of the whole 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); Code: [select]<?php //for error reporting, if no errors delete this... ini_set ("display_errors", "1"); error_reporting(E_ALL); $Res = mysql_query($query_reuniones); if(mysql_num_rows($Res)>0){ ?> <table border="1" align="center" bordercolor="#88D9FF" bgcolor="#D0EEFB"> <tr background="images/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 while($otmp = mysql_fetch_object($Res)){ ?> <tr <?php if ($contador++ % 2) {echo 'class="color"';}?>> <td class="style18"><div align="center" class="style20"><?php echo $otmp['Población']; ?></div></td> <td class="style18"><div align="center" class="style20"><?php echo $otmp['Dirección']; ?></div></td> <td class="style18"><div align="center" class="style20"><?php echo $otmp['Día']; ?></div></td> <td class="style18"><div align="center" class="style20"><?php echo $otmp['Hora']; ?></div></td> <td class="style18"><div align="center" class="style20"><?php echo $otmp['Formato']; ?></div></td> <td class="style18"><div align="center" class="style20"><?php echo $otmp['Observaciones']; ?></div></td> </tr> <?php } ?> </table> <?php } else{ echo 'NO RESULTS FOUND'; } ?> ?><!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> <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> <p align="center" class="style5"> </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); ?> Error log and line as before. What i want is if someone types in the textfield a registry that is not in the "Población" field of DB, instead the Dynamic table, a "NON RESULTS FOUND" would appear. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/135029-help-how-to-draft-correctly-a-php-snippet/#findComment-704649 Share on other sites More sharing options...
haku Posted December 3, 2008 Share Posted December 3, 2008 Code: [select]<?php What exactly is this line supposed to be doing? You definitely don't need the opening php tag. Not sure what Code: [select] is supposed to be accomplishing either. Quote Link to comment https://forums.phpfreaks.com/topic/135029-help-how-to-draft-correctly-a-php-snippet/#findComment-704714 Share on other sites More sharing options...
hookit Posted December 3, 2008 Author Share Posted December 3, 2008 The code im pasting here is working properly: <?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> <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> <p align="center" class="style5"> </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); ?> What i want to implement is that went a user type in the textfield's webpage any word that is not in the database instead empty the dynamic table should appear a message saying something like "NO RESULTS WERE FOUND". And I couldn´t achieve it so far. Quote Link to comment https://forums.phpfreaks.com/topic/135029-help-how-to-draft-correctly-a-php-snippet/#findComment-704745 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.