slaterino Posted January 27, 2010 Share Posted January 27, 2010 Hi, I created a simple search function where the user enters a value in a form and then clicks to send. Now, I'm trying to work out how I can display a message if there are no successful search results. This is a snippet from the code that I'm using right now and I can't think what I can do to achieve this. Is there a way of putting a conditional statement in here saying that IF the search statement is not LIKE common_name and genus then do something else? This is only a small job so don't want to have to rewrite all my script sorting this one out. Does anyone have any suggestions? if (!empty($_GET['qsearch'])) { $search = mysql_real_escape_string( trim($_GET['qsearch']) ); $catalogue_query .=" WHERE Common_Name LIKE '%$search%' OR Genus LIKE '%$search%'"; } Thanks! Russ Quote Link to comment https://forums.phpfreaks.com/topic/189933-adding-condition-into-mysql-search-function/ Share on other sites More sharing options...
RussellReal Posted January 27, 2010 Share Posted January 27, 2010 <?php if (mysql_num_rows($query)) { while ($row = mysql_fetch_assoc($query)) { // do whatever } } else { // no results found } ?> Quote Link to comment https://forums.phpfreaks.com/topic/189933-adding-condition-into-mysql-search-function/#findComment-1002179 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.