So I have a PHP file where a user will search through questions that are in the database, if they search for something random ('ddwdwdwdw') etc. I want it to output a message saying that nothing was returned. However I'm having a little trouble, it might be because my code isn't set up very well?
I've tried doing:
if(mysql_num_rows($sql) < 1){
echo "blah blah blah";
}
But it outputs a MySQL error because the sql fails(which obviously in this case isnt a bad thing). And it outputted the echo message with every type of search, so maybe it was in the wrong position. Thanks for any help, and please ask if I havent made sense.
Form Code:
<html>
<head>
<title>Physics</title>
</head>
<body>
<p> Search for a question type. </p>
<form action = "searchingQuestions.php" method= "POST">
<select name= "Type_DROP">
Question type:
<option value = "NULL"></option>
<option value="SUVAT">Suvat</option>
<option value="FORCES">Forces</option>
<option value="WORK">Work</option>
<option value="Energy">Energy</option>
<option value = "ALL"> All </option>
</select>
<br>
<br>
<p> Or search for a certain text.</p>
<input type = "text" name = "text_try">
<br><br>
<p>Would you like to search through revision questions as well, check if you would like to. </p>
<input type = "checkbox" name = "checkbox" value = "value1">
<br><br>
<input type = "submit" id="submit" value="search">
<div id= "name-data"></div>
</form>
</body>
</html>
num_rows. imo, testing 'number of rows returned' is rarely useful as you want to process the data anyway and you always have an 'end of rows test' in thefetch loop.