kvnirvana Posted May 19, 2010 Share Posted May 19, 2010 I’ve got a search function from three drop down lists It works fine, but if there is no results from the search it just shows a blank page where it should show the message ”No results!” What is wrong? function search() { //base sql $sql = "select * from behan WHERE 1=1"; //get the values from the form //NOTE: You should do way more valdation on the values before you attempt to process anything if ((!isset($_POST['submit'])) && ($_POST['beha'] != 'choose')) { search();} else { if ($_POST['beha'] == ' choose ') { echo "error beha!<br>"; } } { $sql .= " and beha like '". addslashes($_POST['beha'])."%' "; } if ((!isset($_POST['submit'])) && ($_POST['omraede'] != ' choose ')) { search();} else { if ($_POST['omraede'] == ' choose ') { echo "error område!<br>"; } } { $sql .= " and omraede like '". addslashes($_POST['omraede'])."%' "; } if ((!isset($_POST['submit'])) && ($_POST['pr'] != ' choose ')) { search();} else { if ($_POST['pr'] == ' choose ') { echo "error pr!"; } } { $sql .= " and problem = '". addslashes($_POST['problem'])."' "; } // ADD ORDER BY $sql .= ' order by total_value DESC '; print "<table border=1>"; //run query $result = conn($sql); if (!$result){ die("No results due to database error.<br>".mysql_error()); } if (mysql_num_rows($result)==0 && mysql_num_rows($result)!=' choose ') { echo "No results!"; } Link to comment https://forums.phpfreaks.com/topic/202256-doesnt-show-message-when-no-results/ Share on other sites More sharing options...
andrewgauger Posted May 19, 2010 Share Posted May 19, 2010 Remove: && mysql_num_rows($result)!=' choose ' mysql_num_rows will never return a string and as such will never qualify the if statement. Link to comment https://forums.phpfreaks.com/topic/202256-doesnt-show-message-when-no-results/#findComment-1060627 Share on other sites More sharing options...
kvnirvana Posted May 19, 2010 Author Share Posted May 19, 2010 Ok, but I need it to be like show the message if $result=0 and the word 'choose' is not chosen from the drop down. how can I do that? Link to comment https://forums.phpfreaks.com/topic/202256-doesnt-show-message-when-no-results/#findComment-1060760 Share on other sites More sharing options...
kvnirvana Posted May 20, 2010 Author Share Posted May 20, 2010 Anybody? Link to comment https://forums.phpfreaks.com/topic/202256-doesnt-show-message-when-no-results/#findComment-1061086 Share on other sites More sharing options...
andrewgauger Posted May 21, 2010 Share Posted May 21, 2010 You already handled that with: ($_POST['beha'] != 'choose')) earlier in the script. Link to comment https://forums.phpfreaks.com/topic/202256-doesnt-show-message-when-no-results/#findComment-1061472 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.