开发者

Array not resetting

开发者 https://www.devze.com 2023-03-20 03:51 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消