Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.