Edit using foreach (Edited)

Asked

Viewed 51 times

1

Good evening. I have a form where I want to edit some information from a certain sector. Since the select Eps are a foreach of the bank, but I want the ones I want to edit to be selected, however, in addition to selecting they are being duplicated. Follows the code:

<select title="Selecione os EPIs" multiple>

   <?php 

      $epi_explode = explode(',', $result->setor_EPI);

      foreach ($epis as $epi)
      { 
           foreach ($epi_explode as $epi_array)
           { ?>                   
              <option <?=$epi_array == $epi->epi_Nome ? 'selected' : '';?> > 
                  <?=$epi->epi_Nome?>
              </option>

     <?php } } ?>

</select>

Controler:

    public function index()
{   
    $data = array
    (
        'title' => 'Edição de Setores',
        'epis' => $this->setor_model->getEpis(),
    );

    $this->load->view('frame/cabecalho');
    $this->load->view('frame/navegacao');
    $this->load->view('setor/cadastro', $data);
}

Model da Query.

    public function getEpis()
{
    $this->db->select('*');
    $this->db->from('epi');
    return $this->db->get()->result();         
}

Follow the image of how to list the results.

inserir a descrição da imagem aqui

The select list of the epi equipment, however I want only those that are in the database to be selected, because this is a page to edit such sector.

  • Also paste the result of the loop that appears after running the code for a better understanding.

  • Can someone help me?

  • puts the database structure here, the QUERY, completes the question, otherwise it is difficult

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.