h4r00n Posted September 4, 2009 Share Posted September 4, 2009 Hi guys, I have a search form and it is working perfectly, but when a result is not found, it states nothing found but it also shows this message: Notice: Undefined variable: results in C:\Documents and Settings\My Documents\wamp\www\Pages\search.php on line 282 and line 282 is }else{return $results;} the whole coding for that section is function getResults($db,$masterQuery){ $query = $db->query($masterQuery); if(@$db->numRows($query)>0){ //we have a result while($row=$db->fetchArray($query)){$results[] = $row;} @mysql_free_result($query); return $results; }else{return $results;} Quote Link to comment https://forums.phpfreaks.com/topic/173126-error-message-in-search-form/ Share on other sites More sharing options...
taquitosensei Posted September 4, 2009 Share Posted September 4, 2009 it's because $results isn't defined yet. here's how I would do this function getResults($db,$masterQuery){ $results=False; $query = $db->query($masterQuery); //we have a result while($row=$db->fetchArray($query)){$results[] = $row;} @mysql_free_result($query); } return $results; } Then you can just check for results on the next page and if it's true do whatever you need to do. Quote Link to comment https://forums.phpfreaks.com/topic/173126-error-message-in-search-form/#findComment-912506 Share on other sites More sharing options...
h4r00n Posted September 4, 2009 Author Share Posted September 4, 2009 it's because $results isn't defined yet. here's how I would do this function getResults($db,$masterQuery){ $results=False; $query = $db->query($masterQuery); //we have a result while($row=$db->fetchArray($query)){$results[] = $row;} @mysql_free_result($query); } return $results; } Then you can just check for results on the next page and if it's true do whatever you need to do. With the above coding, it shows NOTHING FOUND which is good but no results are shown at all. It sticks to NOTHING FOUND. Quote Link to comment https://forums.phpfreaks.com/topic/173126-error-message-in-search-form/#findComment-912584 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.