0

我解决不了这个。

我有多个while,而里面的那个只获取第一个结果并停止......

这是代码:

$categories 是一个数组

array(18) {
  [0] => array(7) {
["category_id"] => string(1) "1"
["category_name"] => string(5) "pizza"
["category_display"] => string(5) "pizza"
["category_active"] => string(1) "1"
["category_parent"] => string(1) "0"
["category_position"] => string(1) "1"
["category_user_discount"] => string(2) "50"
}
[1] => array(7) {
["category_id"] => string(1) "2"
["category_name"] => string(4) "menu"
["category_display"] => string(4) "menu"
["category_active"] => string(1) "1"
["category_parent"] => string(1) "0"
["category_position"] => string(1) "2"
["category_user_discount"] => string(2) "30"
}
}

$stmt = $db->query("SELECT sell_id FROM sell WHERE sell.sell_status = 'close' AND sell_period_id >= '".$liste[0]."' AND sell_period_id <= '".$liste[1]."' ");

foreach ($categories as $cat)
{
    while ($sell2 = $stmt->fetch())
    {
        $stmt2 = $this->db->query("SELECT * FROM sellcart WHERE sellcart_status = 'close' AND sellcart_sell_id =  '".$sell2['sell_id']."' ");

        while ($sellitem = $stmt2->fetch())
        {
            echo $sellitem['sellcart_item_category'];
        }
    }
}

第一个循环没问题,但它不会循环到第二个 $cat ...

任何想法 ?

谢谢你的帮助 !!!

4

1 回答 1

0

我知道答案为时已晚,但问题是,在第二次 fetch php 关闭连接或第一次 fetch 没有更多值并返回 false 之后。也许您可以尝试使用第二个连接进行第二次提取。

对不起我的英语不好。

// for example ..............
$db = Zend_Db::factory($config["database"]["adapter"],$config["database"]        ["params"]);
$db2 = $db = Zend_Db::factory($config["database"]["adapter"],$config["database"]["params"]);
//  .......
$stmt = $db->query("SELECT sell_id FROM sell WHERE sell.sell_status = 'close' AND sell_period_id >= '".$liste[0]."' AND sell_period_id <= '".$liste[1]."' ");

foreach ($categories as $cat) {
    while ($sell2 = $stmt->fetch()) {
        $stmt2 = $db2->query("SELECT * FROM sellcart WHERE sellcart_status = 'close' AND sellcart_sell_id =  '".$sell2['sell_id']."' ");

        while ($sellitem = $stmt2->fetch()) {
            echo $sellitem['sellcart_item_category'];
        }
    }
}
于 2015-09-18T09:17:33.870 回答