2011-07-13 41 views
0

我在我的php中有一個循環,它接受兩個表的數據庫值並將它們顯示在CodeIgniter下拉列表中 - 但是,在news_types循環之後,數組不會自行重置,它會使用類別數據。 。誰能幫我?Array not resetting

感謝

//inside a loop 

if(isset($news_types)) { 
    foreach($news_types as $type) { 
     $options[$type['id']] = ucwords($type['type']); 
    } 
} 

if(isset($categories)) { 
    foreach($categories as $category) { 
     $options[$category['id']] = ucwords($category['category']); 
    } 
} 

echo '<p>'; 
echo format_label($field); 
echo form_dropdown($field, $options, check_value($field, $submitted, $record->$field)); 
echo '</p>'; 

回答

1

如果您的新聞類型ID的比賽了類別ID,他們將被覆蓋......請嘗試驗證

if(isset($news_types)) { 
    foreach($news_types as $type) { 
     $options["news_".$type['id']] = ucwords($type['type']); 
    } 
} 

if(isset($categories)) { 
    foreach($categories as $category) { 
     $options["cat_".$category['id']] = ucwords($category['category']); 
    } 
} 

前綴你的ID,以確保它們不衝突。