PHP runs until the page returns to the browser. When you see the page in your browser, all PHP is already executed. What you probably want to do is use AJAX. Here is a general description of how you will do this:
You have a PHP page that takes an identifier and returns the data you need as JSON.
api.php
$theId = $_POST['theId']; //Get the information you want, and turn it into an array called $data header('Content-Type: application/json'); echo json_encode($data);
In your html, you should run the modal version using the onclick binding to View Comments:
<a class="xyz" onclick = "launch_comment_modal(<?php echo $list[$i]->getID(); ?>)">View Comments</a>
then below with your other javascript:
<script> $('#compose-modal').modal({ show: false}); function launch_comment_modal(id){ $.ajax({ type: "POST", url: "api.php", data: {theId:id}, success: function(data){ </script>
source share