Invalid argument supplied for foreach
Posted: Wed Feb 17, 2010 2:37 pm
Hello, All. Here's the deal:
I have a script which instantiates a class thusly:
As you can see, I'm passing the $_GET array to the constructor of the search_results class. Within the constructor of that class, I assign $_GET to $this->queryString, like so:
Then, I iterate through $this->queryString in a member function:
The intent of the code is achieved: a search is performed (a select query constructed) using only those fields for which criteria were entered by the user. However, I get an "Invalid argument supplied for foreach()" warning for the foreach loop in the member function (line 3) above. Can't figure out why. I've "echo'd" $this->queryString, which outputs, as expected, "Array()". I've "print_r"'d the array, and the associative array is printed out. Any ideas? Thanks.
I have a script which instantiates a class thusly:
Code: Select all
$searchResultsObject = new search_results($_GET,'simple');
Code: Select all
function __construct($queryString,$type) {
. . .
$this->queryString = $queryString;
. . .
}
Code: Select all
private function set_searchFields() {
foreach ($this->queryString as $field => $value) {
//don't deal with search button portion of the query string
if ($field != 'submit') {
//but deal with everything else here
if ($value != '') {
//these are the criteria entered
$this->searchFields[$field] = $value;
}
}
}
}