我有一个数组,一个例子是..
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
)
)
现在,关键是一个 MySQL 数据集,使用;cats
循环没有问题。mysql_fetch_array
但是一旦进入该循环,我尝试在列表数组的某个键上运行另一个循环,例如home-and-garden
,列表数组下的所有键都是动态的,所以我必须传入一个带有键名的变量,但是它不会t 进入循环。
下面是我的代码示例..
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
}
}
}
编辑:一个例子$sql['listings'][$main_category_slug]
的转储如下:
resource(55) of type (mysql result)
转储$sql['listings']
如下:
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)
}
它们似乎都是有效的资源,我检查了密钥名称是否正确。