简体   繁体   English

在动态mysql数据数组循环中遇到问题

[英]Having issue with looping through dynamic mysql data array

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 ; 现在, cats键是一个MySQL数据集,在使用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. 但是,一旦进入该循环,我就尝试对清单数组的某个键(例如home-and-garden运行另一个循环,清单数组下的所有键都是动态的,因此我必须传递一个具有键名的变量,但是它不会进入循环。

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: 编辑:示例$sql['listings'][$main_category_slug]如下:

resource(55) of type (mysql result) 

Dump of $sql['listings'] is below: $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)
}

They all appear to be valid resources and I have checked that the key name is correct. 它们似乎都是有效的资源,我已经检查了密钥名称是否正确。

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. 如果遇到这样的问题,请始终输出相应的查询并手动运行它,以查看结果集是否为空。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM