How to filter a foreach for a select

0

Good afternoon,

I have this code:

<div class="modal-body">
<p><?php echo $ee['Establecimiento']; ?> have <?php echo $totalbooks; ?> books.</p>
<p> Do you wish to move all the books to another library?</p>
<form method="post" action="<?php echo $CRDomain; ?>assets/private/library/establecimiento.php">
<input type="hidden" value="<?php echo $ee['IDEstablecimiento']; ?>" name="id" />
<input type="hidden" name="action" value="move"/>
<div class="form-group">
    <div class="col-md-8">
        <select class="form-control" name="tothis" required>
        <?php foreach ($establecimiento as $gg): ?>
            <option value="<?php echo $gg['IDEstablecimiento']; ?>"><?php echo $gg['Establecimiento']; ?></option>
        <?php endforeach; ?>
        </select>
    </div>
    <button type="submit" class="btn sbold green-jungle cold-md-4"> Move and Suspend </button>
</div>
</form>

<p>Or you can also suspend the library and leave the books in it</p>

<form method="post" action="<?php echo $CRDomain; ?>assets/private/library/establecimiento.php">
    <input type="hidden" value="<?php echo $ee['IDEstablecimiento']; ?>" name="id" />
    <input type="hidden" name="action" value="suspend"/>
    <button type="submit" class="btn sbold red-thunderbird"> Suspend </button>
</form>

Basically what it does is to be able to eliminate an establishment, see if there are books assigned to that establishment, if it opens a modal (the code above) and gives the option to cancel it with books in the establishment , or transfer the books to another establishment.

In the select, it lists the establishments. Well, the question is (I'm very lost with this) as not showing the main establishment (which is going to transfer the books to another) as it makes no sense to move the books to the same establishment.

Does anyone have any idea how to filter the foreach and not show the establishment that is being removed?

Thanks in advance.

    
asked by Charlie Clewer 15.06.2017 в 17:29
source

1 answer

0

The name of the establishment is at the beginning $ee['Establecimiento']; and within the foreach you have $gg['Establecimiento']

Within foreach you can create a if

<?php foreach ($establecimiento as $gg): ?>
   <? if ($ee['Establecimiento'] != $gg['Establecimiento']) ?>
       <option value="<?php echo $gg['IDEstablecimiento']; ?>"><?php echo $gg['Establecimiento']; ?></option>
   ?>
<?php endforeach; ?>

When visiting the establishments, the condition that you add, would be to verify if the name of the establishment you are visiting is different from the one you have, load the available selectors.

    
answered by 15.06.2017 / 17:33
source