【问题标题】:How do I get my modal information to show, while trying to make it dynamic?如何在尝试使其动态化的同时显示我的模态信息?
【发布时间】:2017-08-24 05:05:22
【问题描述】:

在单击特定图像后,尝试打开一个模式,该模式应该从我的数据库中获取信息并将其呈现到模式上。模态弹出,但它显示在 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">&times;</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>

【问题讨论】:

    标签: php html mysql


    【解决方案1】:

    你检查过 $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 ]";
    }
    ?>
    

    有区别吗?

    【讨论】:

    • 同样的问题
    • $id 在 $sql = "SELECT * FROM rent WHERE rent_id = '$id'" 之前返回什么?你能附和并告诉我们吗?
    猜你喜欢
    • 1970-01-01
    • 2021-08-01
    • 2012-03-30
    • 2020-11-15
    • 2020-03-17
    • 2022-12-12
    • 1970-01-01
    • 1970-01-01
    • 2020-12-06
    相关资源
    最近更新 更多