Reputation: 20049
I have an array, an example being..
Array
(
[cats] => Resource id #54
[listings] => Array
(
[home-and-garden] => Resource id #55
[professional-services] => Resource id #56
[community] => Resource id #57
[education-and-instruction] => Resource id #58
[automotive] => Resource id #59
[legal-and-financial] => Resource id #60
)
)
Now, the cats
key is a MySQL data set, which I have no issues looping through with mysql_fetch_array
; however once inside that loop I try and run another loop on a certain key of the listings array, such as home-and-garden
, all the keys under the listings array are dynamic, so I have to pass in a variable with the key name, however it won't enter the loop.
Below is an example of my code..
protected function makePopularCategoryHTML($sql) {
while (list($main_category,$slug,$image)=mysql_fetch_array($sql['cats'])) {
// Make lowercase category slug
$main_category_slug = URLSafe($main_category);
while (list($category,$name,$tag1,$newurl)=mysql_fetch_array($sql['listings'][$main_category_slug])) {
// It won't enter this loop
}
}
}
Edit: Dump of an example $sql['listings'][$main_category_slug]
is below:
resource(55) of type (mysql result)
Dump of $sql['listings']
is below:
array(6) {
["professional-services"]=>
resource(55) of type (mysql result)
["home-and-garden"]=>
resource(56) of type (mysql result)
["community"]=>
resource(57) of type (mysql result)
["food-and-dining"]=>
resource(58) of type (mysql result)
["real-estate"]=>
resource(59) of type (mysql result)
["business-to-business"]=>
resource(60) of type (mysql result)
}
They all appear to be valid resources and I have checked that the key name is correct.
Upvotes: 0
Views: 761
Reputation: 20049
The array it wouldn't go into was empty because I assumed since I wasn't getting any errors from the respective queries that the query was ok, but it wasn't - one of the search parameters was blank.
If you are getting problems like this, always output the respective query and run it manually to see if you have an empty result set.
Upvotes: 1