svital Posted August 15, 2008 Share Posted August 15, 2008 I am using Dreamweaver CS3 to connect to a MySQL database and do a search. Dreamweaver created the code for me, but I need to enhance the function to include an error check which handles a "no results found". Everything I have tried has caused the page to not display at all? I have no idea how to change my little script to include this? Can anyone help? This is the code from the searchresults.php ****************CODE**************************** <?php require_once('../Connections/MySQL2.php'); ?> <?php $currentPage = $_SERVER["PHP_SELF"]; $colname_search = "-1"; if (isset($_GET['title'])) { $colname_search = (get_magic_quotes_gpc()) ? $_GET['title'] : addslashes($_GET['title']); } mysql_select_db($database_MySQL2, $MySQL2); $query_search = sprintf("SELECT * FROM items WHERE description LIKE '%%%s%%' ORDER BY items.Description", $colname_search); $search = mysql_query($query_search, $MySQL2) or die(mysql_error()); $row_search = mysql_fetch_assoc($search); $totalRows_search = mysql_num_rows($search); $queryString_Desription = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_Desription") == false && stristr($param, "totalRows_Desription") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_Desription = "&" . htmlentities(implode("&", $newParams)); } } $queryString_Desription = sprintf("&totalRows_Desription=%d%s", $totalRows_Desription, $queryString_Desription); ?> <?php require_once('../Connections/MySQL2.php'); ?> .... <?php do { ?> <table width="50%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td class="style5"><?php echo $row_search['Description']; ?></td> </tr> </table> <?php } while ($row_search = mysql_fetch_assoc($search)); ?> *****************END CODE**************************************** Quote Link to comment https://forums.phpfreaks.com/topic/119908-solved-not-very-good-with-php-and-need-help/ Share on other sites More sharing options...
wildteen88 Posted August 16, 2008 Share Posted August 16, 2008 I presume you could change <?php do { ?> <table width="50%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td class="style5"><?php echo $row_search['Description']; ?></td> </tr> </table> <?php } while ($row_search = mysql_fetch_assoc($search)); ?> to <?php if($totalRows_search > 0) { do { ?> <table width="50%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td class="style5"><?php echo $row_search['Description']; ?></td> </tr> </table> <?php } while ($row_search = mysql_fetch_assoc($search)); } else { echo 'No results forund'; } ?> However you'll be better of coding the script yourself, that way you know what is happening in your script. Letting Dreamweaver do it for only complicates things, as the generated code is messy and alot of is not needed. The above code could be written to around 10 lines max. Quote Link to comment https://forums.phpfreaks.com/topic/119908-solved-not-very-good-with-php-and-need-help/#findComment-617922 Share on other sites More sharing options...
svital Posted August 16, 2008 Author Share Posted August 16, 2008 That works great. Thanks very much for sharing!!! Best Regards, Sondra Quote Link to comment https://forums.phpfreaks.com/topic/119908-solved-not-very-good-with-php-and-need-help/#findComment-617948 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.