Modal does not load the data that is coming from the database correctly

Asked

Viewed 102 times

0

Good morning.

Guys, I got a little problem here.

I am showing in the view a table, where if a column has a certain status will show a link to open a model where will be shown the data that are in the database.

I gave a var_dump in the array and the data is coming correct, but it does not take the related Row data at the foreach position, it always repeats as if it were the first line.

VIEW>

<?php if($role['dr_status'] == "3") { ?>
                            <!-- <?php $desligamento = $this->Clinic_model->get_cancel_description($role['dr_id']); ?>
                            <?php var_dump($desligamento) ?> -->
                            <span style="color: red; font-weight:600"><?php echo "Desligamento solicitado" ?>
                              <a data-toggle="modal" data-target="#exampleModal">
                                <span style="margin-left: 10px; cursor: pointer"> ver motivo </span>
                              </a>
                            </span>
                            <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                <div class="modal-dialog" role="document">
                                  <div class="modal-content">
                                    <div class="modal-header" style="background-color: #00C0EF; color: white; font-weight: 600">
                                      <h5 class="modal-title" id="exampleModalLabel" style="font-weight: 600">Desligamento solicitado</h5>
                                      <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">&times;</span>
                                      </button>
                                    </div>
                                    <div class="modal-body" style="font-weight: 600">
                                      <p> <?php echo $role['cancel']; ?> </p>
                                    </div>
                                    <div class="modal-footer col-12">
                                      <p> Deseja realmente desligar esse médico </p><br>
                                      <button type="button" class="btn btn-danger">SIM</button>
                                      <button type="button" class="btn btn-secondary" data-dismiss="modal">Voltar</button>
                                    </div>
                                  </div>
                                </div>
                              </div>
                          <?php } ?>

essa é a tabela que estou criando, quando clica em ver detalhes abre o modal

this is the table I’m creating, when click on details opens the modal > inserir a descrição da imagem aqui

And here’s the problem all the modals always show the same data, I think it’s related to the DOM, but I couldn’t solve the problem. Preferably if done in php itself.

thank you.

  • You are using ajax to make data requests?

  • no, I’m using php itself with codeigniter framework.

  • 1

    I suggest that each link has an id, and that when you click on the link open a modal run an ajax that does the query in the database and print in the body of the modal.

1 answer

2


What you need to do is, create a modal for each item. And what you’re probably doing is creating a single modal and saying that all the items point to that modal. What you could do is, at div modal, put some identifier, such as the item’s own ID in your DB.

para cada $registro:
    <a data-toggle="modal" data-target="#exampleModal-<?php echo $registro->id; ?>">
        ...
    <div class="modal fade" id="exampleModal-<?php echo $registro->id; ?>">
        ...
  • 2

    The idea is good, but won’t delay loading the page? if it has 100 records, be created 100 modals? would not be more interesting a modal unico that would return the data from the chosen record?

  • 1

    then... well, it could create a single modal, and when it is clicked on the display button, it query via ajax the bank, and feed the modal with the returned data, as you said.

  • I created the ids according to the records in the database, but how do I access this when the user gives a click? can be using jquery > $("#btn_modal"). click(Function(){... }

Browser other questions tagged

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