Create dynamic Divs (Codeigniter)

Asked

Viewed 33 times

1

I need to create multiple Ivs inside a foreach in my view, so far so view:

<?php
    echo form_open('admin/marcacao/registraMarcacoes');
  ?>
    <div class="area-imagem">
      <img src="<?= $img?>" alt="<?= $img?>">
      <input style="display:none;" name="idImg" value="<?= $id?>">
      <?php foreach ($marcacoes->result() as $row) : ?>
        <div class="pixel" style="top:<?php echo $row->coordX ?>px; left:<?php echo $row->coordY ?>px"></div>
      <?php endforeach ?>
    </div>
    <input style="display:none;" type="submit" class="btn btn-primary btn-lg my-5 mx-5" value="Registrar">
  <?php 
    echo form_close(); 
  ?>

My controller is like this:

function insereMarcacoes()
    {
        $dados['img'] = $this->input->post('src');
        $dados['id'] = $this->input->post('id');

        $this->load->model('admin/tbdmarcacao');
        $dados['marcacoes'] = $this->tbdmarcacao->listaMarcacoes();

        $this->load->view('admin/inserir_marcacoes', $dados);
    }

And my model this way:

function listaMarcacoes()
    {
        $id['idImagem'] = $this->input->post('id');

        $query = $this->db->select('*')
                            ->from('tbdmarcacao')
                            ->where('idImagem', $id)
                            ->get();

        return $query->result_array();


    }

The problem is that it is returning several errors, as shown in this print:

inserir a descrição da imagem aqui

1 answer

0

The problem is in Model. Note that $id['idImagem'] = $this->input->post('id'); inserts the post value in the index idImagem and in the where query is passed the whole array and not only the index id. So Where should look like this: ->where('idImagem', $id['idImagem']).

Browser other questions tagged

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