尝试打开一个模式,该模式应在单击特定图像后从我的数据库中获取信息并将其呈现到模式中。模式弹出,但它显示在 html 输入上,没有显示在任何 php 输入上。我怎样才能解决这个问题? rental_id 是数据库表中的主要。
<?php
require_once '../core/init.php';
$id = $_POST['rental_id'];
$id = (int)$id;
$sql = "SELECT * FROM rental WHERE rental_id = '$id'";
$result = $db->query($sql);
$rental = mysqli_fetch_assoc($result);
?>
<!-- the div that represents the modal for the form -->
<?php ob_start();?>
<div class="modal fade" id="quote" tabindex="-1" role="dialog" aria-labelledby="quote" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button class="close" type="button" data-dismiss='modal' aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title text-center">Quote</h4>
</div>
<div class="modal-body">
<div class="container-fluid">
<div class="row">
<div class="col-sm-6">
<div class="center-block">
<img src="<?= $rental['img']; ?>" alt="<?= $rental['make']; ?>" class="w3-image img-responsive"/>
</div>...
和...
<script>
function detailsmodal(rental_id){
var data = {"rental_id" : rental_id};
jQuery.ajax({
url : <?php echo BASEURL;?> + 'includes/detailsmodal.php',
method : "post",
data : data,
success: function(data){
jQuery('body').append(data);
jQuery('#quote').modal('show');
},
error: function(){
alert("Something went wrong!");
}
});
}
</script>
最佳答案
你检查过 $id = (int)$id; ?设置好了吗? 任何返回错误信息? ( SO question )
<?php
print_r($rental); /* seems ok when tested with ie: $id=3 */
$sql = " SELECT img, make FROM rental WHERE rental_id=? ";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param("s", $id);
$results = $stmt->execute();
$stmt->bind_result($img, $make);
$stmt->store_result();
while($stmt->fetch()){
echo"[ $img / $make ]";
}
?>
有区别吗?
关于php - 如何让我的模态信息显示出来,同时尝试使其动态化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43115042/