2011-07-13 40 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,以确保它们不冲突。