maximus83 Posted August 16, 2011 Share Posted August 16, 2011 Hi, I'm trying to get a no results returned message to appear after a search form, but at the moment I get the message when the user searches no matter if there are results or not. Could someone please look at my code below and tell me where I am going wrong. Many thanks. if ($_POST["search"]) { $query = "SELECT ticket_number, first_name, surname, email, product, retailer, DATE_FORMAT(dop, '%d %M %Y') AS dop, message, address, DATE_FORMAT(created, '%d %M %Y %r') AS created, status FROM support_dev WHERE ticket_number LIKE '$search' OR email LIKE '$search' ORDER BY ticket_number DESC LIMIT $start, $display"; if (mysql_num_rows($result) < 1) { echo 'Please try another search term.'; } else { if ($result = mysql_query ($query)) { echo ' <div id="supviewwrapperheader"> <div id="supviewticket"><p>Ticket</p></div> <div id="supviewfirst"><p>First Name</p></div> <div id="supviewlast"><p>Last Name</p></div> <div id="supviewemail"><p>Email</p></div> <div id="supviewproduct"><p>Product</p></div> <div id="supviewretailer"><p>Retailer</p></div> <div id="supviewdop"><p>D.O.P.</p></div> <div id="supviewmessage"><p>Message</p></div> <div id="supviewaddress"><p>Address</p></div> <div id="supviewcreated"><p>Date created</p></div> <div id="supviewstatus"><p>Status</p></div> <div id="supviewbuttons"><p></p></div> </div> '; while ($row = mysql_fetch_array($result, MYSQL_NUM)) { echo " <div id=\"supviewwrapper\" class=\"".($row[10])."\"> <div id=\"supviewticket\"><p><a name=\"a".$row[0]."\"></a>$row[0]</p></div> <div id=\"supviewfirst\"><p>$row[1]</p></div> <div id=\"supviewlast\"><p>$row[2]</p></div> <div id=\"supviewemail\"><p>$row[3]</p></div> <div id=\"supviewproduct\"><p>$row[4]</p></div> <div id=\"supviewretailer\"><p>$row[5]</p></div> <div id=\"supviewdop\"><p>$row[6]</p></div> <div id=\"supviewmessage\"><p>$row[7]</p></div> <div id=\"supviewaddress\"><p>$row[8]</p></div> <div id=\"supviewcreated\"><p>$row[9]</p></div> <div id=\"supviewstatus\"><p>$row[10]</p></div> <div id=\"supviewbuttons\"><p><form method=\"post\" action=\"".htmlentities($_SERVER['REQUEST_URL'])."#a".$row[0]."\"><input type=\"hidden\" name=\"close_row\" value=\"".($row[0])."\" /><input type=\"hidden\" name=\"viewstate\" value=\"".$viewstate."\" /><INPUT TYPE=\"submit\" name=\"open\" VALUE=\"\" class=\"submit_open\"><br /><INPUT TYPE=\"submit\" name=\"pending\" VALUE=\"\" class=\"submit_pending\"><br /><INPUT TYPE=\"submit\" name=\"pending_ami\" VALUE=\"\" class=\"submit_pendingami\"><br /><INPUT TYPE=\"submit\" name=\"pending_arp\" VALUE=\"\" class=\"submit_pendingarp\"><br /><INPUT TYPE=\"submit\" name=\"close\" VALUE=\"\" class=\"submit_closed\"></form></p></div></div>"; } }} } Quote Link to comment https://forums.phpfreaks.com/topic/244933-no-search-results-message-even-when-results-returned/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 16, 2011 Share Posted August 16, 2011 You are trying to use the $result from the mysql_query() statement in this statement - mysql_num_rows($result), before you have even executed the query in this statement - $result = mysql_query ($query) Quote Link to comment https://forums.phpfreaks.com/topic/244933-no-search-results-message-even-when-results-returned/#findComment-1258167 Share on other sites More sharing options...
maximus83 Posted August 16, 2011 Author Share Posted August 16, 2011 thanks man, sorted it now. Quote Link to comment https://forums.phpfreaks.com/topic/244933-no-search-results-message-even-when-results-returned/#findComment-1258175 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.