简体   繁体   中英

Passing PHP variable through pop-up link

I need to pass a variable through the link when calling a pop up window. When adding a variable like I normally would the names don't match up with the pop up window.

This is what I have:

<a data-toggle="modal" href="#allMessages?id=<?php echo $job['job_id']; ?>" class="btn btn-warning btn-sm btn-icon">
  <i class="fa fa-unlock-alt"></i>View All Messages
</a>


    <div class="modal fade" id="allMessages" tabindex="-1" role="dialog" aria-labelledby="allMessages" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header success">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i></button>



                            <h4 class="modal-title">Reply</h4>
                        </div>
                            <?php
                                $getMessages = mysqli_query($mysqli, 
                                "SELECT *
                                FROM messages 
                                WHERE messages.job_id = $GET['id']
                                "
                                );

                                $messages = array(); 
                                    while($message = mysqli_fetch_assoc($getMessages)) {
                                          $messages[] = $message;
                                }

The problem is when I add the variable at the end of the button link #allMessages?id= it no longer calls the pop-up window.

Javascript:

        $("[data-toggle='popover']").popover();

});

function load_page() {
    var selected_page = document.getElementById("selected_page").value;
    if (selected_page != "") {
        window.location.href = selected_page
        //Please note that the value recived,
        //in this case selected_page,
        //should be a valid url!
        //Therefore the value of the
        //<option> tag should be itself 
        //a url !
        //ex.: <option value="page.php"> is valid
        //<option value="page_1"> is not valid
    }

I can't see this working.

The modal is already on the page, just invisible so any PHP queries would be done when the page is rendered, not when the modal is activated.

Personally I'd send the ID over in a data attribute, do the processing in an AJAX request and then push the results into the modal box.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM