Jump to content

error message in search form


h4r00n

Recommended Posts

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;}

Link to comment
https://forums.phpfreaks.com/topic/173126-error-message-in-search-form/
Share on other sites

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.