如何在模式对话框中定义id(单个id)?

时间:2017-05-25 00:07:03

标签: javascript php

<?php
....
$sql = "SELECT * FROM items ORDER BY item_id DESC";
$query = mysqli_query($con, $sql);
while ($row_item=mysqli_fetch_array($query)){
    $id = $row_item['item_id'];
    $title = $row_item['item_title'];
    $image = $row_item['item_image'];
    $trailer = $row_item['item_trailer'];

    echo "
        <div class='col-sm-3'>
           <img src='item-images/$image' />
           <p>$title</p>
            <a href='' class='launch-modal' data-modal-id='modal-video'>Trailer</a>

            <!--Modal-->
            <div class='modal fade' id='modal-video' tabindex='-1' role='dialog'>
                <div class='modal-dialog'>
                    <div class='modal-content'>
                        <div class='modal-header'>
                            <button type='button' class='close' data-dismiss='modal'>Close</button>
                            <h4 class='modal-title'>$title</h4>
                        </div>
                        <div class='modal-body'>
                            <div class='modal-video'>
                                <video id='video-frame' controls src='item-trailer/$trailer'></video>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div> <!--.col-sm-3-->
    ";
    ?>

如何使用它自己的ID在模态对话框中启动这个$预告片?

我已经尝试了这个,但它不起作用: HREF =&#39;的index.php $ ID&#39;?

仅供参考:这是旧的,没有模态对话框的目标是另一页:

回声&#34;     HREF =&#39; trailer.php single_id = $ ID&#39?; &#34 ;;

<!--The Other Page-->
<?php
if(isset($_GET['single_id'])){
$item_id = $_GET['single_id'];
$get_item = "SELECT * FROM items WHERE item_id='$item_id'";
$run_item = mysqli_query($con, $get_item);
while ($row_item=mysqli_fetch_array($run_item)){

    $theID = $row_item['item_id'];
    $theTitle = $row_item['item_title'];
    $theTrailer = $row_item['item_trailer'];
    echo "
         <video controls src='item-trailer/$theTrailer'></video>
         <p>$theTitle</p>

    ";
}
}
?>

如需更多评论,我会给javasript执行页面:

$(function(){
// open the modal
$('.launch-modal').on('click', function(e){
e.preventDefault();
$( '#' + $(this).data('modal-id') ).modal();
}); // reload the modal contents when it is closed
$("#modal-video").on("hidden.bs.modal", function () {
var url = $('#video-frame').attr('src');
$('#video-frame').attr('src', '');
$('#video-frame').attr('src', url);
});
});

0 个答案:

没有答案