simon0304 Posted December 6, 2004 Share Posted December 6, 2004 Hi all, I have a database for insect species. I have set up a search box which a user can enter a keyword and it pull out any info from the database containing that word. I have two problems. Firstly Everything works ok, but I have just noticed that if no entry is place in the text box and the search button is pressed then everything from the database is displayed. Is there anyway to correct this. the script is as follows SELECT ID, BF, Vernacular, Taxon FROM species WHERE Vernacular LIKE '%colname%' ORDER BY Vernacular ASC Hope you can help Thanks Simon Quote Link to comment https://forums.phpfreaks.com/topic/2081-search-boxes-in-dremaweaver/ Share on other sites More sharing options...
Pilot-Doofy Posted December 22, 2004 Share Posted December 22, 2004 code and stuff Try this, assuming you can change the variables accordingly. // variable for the $_POST $search_string = $_POST['searchfield']; if ($search_string == "") // asking if its empty { echo "Sorry, please <a href=javascript:history.go(-1);>go back</a> and enter something in the search field!"; } elseif ($search_string != "") // if its not empty, you an also use if (!empty($search_string)) { $query = "SELECT ID, BF, Vernacular, Taxon FROM species WHERE Vernacular LIKE '%colname%' ORDER BY Vernacular ASC"; $result = mysql_query($query); $result_total = mysql_num_rows($result); // see how many results were pulled if ($result_total == 0) // if nothing is returned in the search do this { echo "Sorry, no results matched your search criteria."; } if ($result_total > 0) // if results are actually brought up do this { echo "Congratulations! There were $result_total results found matching the criteria you searched for!"; // give loop to show all the results here } else // if something other than that goes wrong { echo "There was a problem outside the magical realm of my knowledge, try again."; } } mysql_close(); // close connections Try that, sorry if its wrong in some ways, I'm studying for my History exam. Quote Link to comment https://forums.phpfreaks.com/topic/2081-search-boxes-in-dremaweaver/#findComment-6878 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.