<?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-->
";
?>
How can i make this $trailer launch inside modal dialog with it's own id?
i already try this but it's not working: href='index.php?$id'
FYI: This is the old one which targeted to the other page without modal dialog:
echo " href='trailer.php?single_id=$id' ";
<!--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>
";
}
}
?>
For more review, i give the javasript that execute the page:
$(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);
});
});