Array not resetting
I have a loop 开发者_开发问答in my php which takes the database values of two tables and displays them in a CodeIgniter dropdown - however the array doesn't reset itself after the news_types loop, it uses the category data instead...can anyone help me?
Thanks
//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>';
If your news type id's match up with category ids they will be overwritten... Try this to verify
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']);
}
}
prefix your ids to make sure they do not clash.
精彩评论