1

I am trying to exclude more than one ID from a select list that is populated by a foreach loop:

$types = new Type();
$types->where('id !=', 13)->order_by('name')->get();
$data['types'] = $types;

<select class="styled" name="form[type_id]">
<option value="0"> - select one - </option>
<?php foreach ($types as $t): ?>
<option value="<?=$t->id?>" <?=check_selected($t->id, $i->type_id)?>><?=$t->name?></option>
<?php endforeach; ?>
<option value="13" <?=check_selected(13, $i->type_id) ?>>Other</option>
</select>

So at the moment it will exclude ID 13 (and add it manually to the bottom), but how do I add more IDs to be excluded?

Thanks in advance.

1 Answer 1

2

try this:

...
$exclude = array(13,25);// add IDs to exlude
....
<?php foreach ($types as $t): ?>
   <?php if(!in_array($t->id, $exclude)){ ?>// if the ID is in the exlude array don't add it
      <option value="<?=$t->id?>" <?=check_selected($t->id, $i->type_id)?>><?=$t->name?></option>
   <?php } ?>
<?php endforeach; ?>
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.