0
我無法解決這個問題。Zend Framework在循環中使用fetch()語句,內部查詢不起作用
我有多個時,和一個內只獲取第一個結果,並停止...
下面是代碼:
$類是一個數組
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'];
}
}
}
第一循環是好的,但它不會循環到第二個$貓...
任何想法?
感謝您的幫助!
很明顯的問題,SQL返回多個結果?可能需要進一步調試以獲得幫助。 – ficuscr
當然可以,不過謝謝您的提問......我認爲有兩個鏈接在丟失時會丟失,但我找不到如何修復它。 當然,我可以使用fetchAll,但數據太大,佔用太多內存,這就是爲什麼我希望使用fetch()... – Altivec