Can i create a modal dynamic id?

I've been trying for some time now to create a modal window that opens with a dynamic id created in php. The identifier is stored in the database and is called when needed to create a custom table.

I want to be able to click on a user and have all my preferences and options in a modal, although as I said above, I need one modal that opens the correct information for the user, depending on which users have the click.

I have the current code displaying users:

if ($result->num_rows > 0) { echo "
<table class='table table-hover'>
  <tr style='font-size:18px;'>
    <th>Name</th>
    <th>Username</th>
  </tr>"; // output data of each row while($row = $result->fetch_assoc()) { echo "
  <tr style='font-size:16px;'>
    <td><a href=\ "#id=$row[username]\">".$row["name"]."</a>
    </td>
    <td style='color:#3c9bce'>".$row["username"]."</td>
  </tr>"; } echo "</table>"; } else { echo "There are 0 clients in the system matching your search criteria";

      

and I tried the following to open the modal way.

<div id="#id=$row[username]">
  <div class="modal-content">
    <div class="header">
      <h4 style="text-align: center;">Use the map below to select the closest agent to the breakdown</h4>
    </div>
    <div class="copy">
      <p>THIS IS A MODAL</p>
    </div>
    <div class="cf footer">
    </div>
  </div>
  <div class="overlay"></div>
</div>

      

Am I using the wrong id for the modal?

+3


source to share


1 answer


I think you can solve this using a little jQuery / Ajax.

$(function() {
     $(document).on("click", "#editData", function () {
     var list = $(this).attr("data-id");
        $('#containerData').html('');  
        $.post("process.php",{list:list},
            function(data){
                $('#containerData').html(data);
             });

         });
     });

      



and process.php

//do whatever you need with the data
$id = $_POST['list'];
echo $id;

      

+1


source







All Articles