adding modal in a loop is an automatic duplication of html content when there is no special need for it! It is not recommended to add modal elements to each element in the loop, and only call data when it is requested!
Here is an example, add the following button to the loop in PHP
<button data-id="<?php echo $note['id']; ?>" onclick="$('#dataid').text($(this).data('id')); $('#showmodal').modal('show');">Click me </button>
on your modal you can use this identifier to query your db or any json
an example assuming you are using a modal called showmodal, use this information to make a new request to your database or wish a class or function!
<?php $dataid = '<span id="dataid"/>'; echo $dataid; ?>
echo $ dataid serves only to show you that the identifier of the selected item in the loop really works.
as you can see here, we add only one HTML template to the loop, and we also only call the data when it is requested! it will save memory and also be faster.
I hope this helps a lot of people
source share