php - 使用mysql和php将动态创建的div数据发送到html模式

时间:2017-07-10 16:55:49

标签: php html mysql loops modal-dialog

1我使用while循环用数据库的数据创建了div。所以它会创建多个div。然后我按钮按开了一个模态。问题是我无法将值传递给我的模态。

这是我的代码:

<style type="text/css">
    .product_view .modal-dialog{max-width: 800px; width: 100%;}
    .pre-cost{text-decoration: line-through; color: #a5a5a5;}
    .space-ten{padding: 10px 0;}
</style>

<body>
    <?php  $result = mysqli_query($conn, "SELECT * FROM table"); ?>
    <div class="container">
        <div class="row">
            <?php 
            while ($row = mysqli_fetch_array($result) )
                {   ?>
            <div class="col-md-4">
                <div class="thumbnail">
                    <img src="<?php echo $row['image']?>" alt="No image" class="img-responsive">
                    <div class="caption">
                        <h4 class="pull-right">$<?php echo $row['a'];?></h4>
                        <h4><a href="#"><?php echo $row['b'];?></a></h4>
                        <p><?php echo $row['c'];?></p>
                    </div>

                    <div class="space-ten"></div>
                    <div class="btn-ground text-center">
                        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#product_view"><i class="fa fa-search"></i><?php $pid = $row['d'];?> Quick View</button>         
                    </div>
                    <div class="space-ten"></div>
                </div>
            </div>
            <?php } ?>

        </div>
    </div>

    <div class="modal fade product_view" id="product_view">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <a href="#" data-dismiss="modal" class="class pull-right"><span class="glyphicon glyphicon-remove"></span></a>
                    <h3 class="modal-title"><?php echo $row['d'];?></h3>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-6 product_img">
                            <img src="http://img.bbystatic.com/BestBuy_US/images/products/5613/5613060_sd.jpg" class="img-responsive">
                        </div>
                        <div class="col-md-6 product_content">
                            <h4>Product Id: <span>Here Should come $row['b'] of selected one</span></h4>

                            <p> Here Should come $row['c'].</p>

                            <div class="space-ten"></div>
                            <div class="btn-ground">
                                <button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-shopping-cart"></span>Here Should come  $row['a']</button>
                                <button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-heart"></span>Here Should come $row['b']</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

example of divs now lets click for 1 div的例子现在让我们点击1

This is what I'll get in echo $row 他是我的模式中的echo $ row,最后一个值是9。

知道我错过了什么吗?谢谢

1 个答案:

答案 0 :(得分:0)

<style type="text/css">
.product_view .modal-dialog{max-width: 800px; width: 100%;}
.pre-cost{text-decoration: line-through; color: #a5a5a5;}
.space-ten{padding: 10px 0;}
</style>

<body>
<?php  $result = mysqli_query($conn, "SELECT * FROM table"); ?>
<div class="container">
    <div class="row">
        <?php 
        while ($row = mysqli_fetch_array($result) ): ?>
        <div class="col-md-4">
            <div class="thumbnail">
                <img src="<?php echo $row['image']?>" alt="No image" class="img-responsive">
                <div class="caption">
                    <h4 class="pull-right">$<?php echo $row['a'];?></h4>
                    <h4><a href="#"><?php echo $row['b'];?></a></h4>
                    <p><?php echo $row['c'];?></p>
                </div>

                <div class="space-ten"></div>
                <div class="btn-ground text-center">
                    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#product_view"><i class="fa fa-search"></i><?php $pid = $row['d'];?> Quick View</button>         
                </div>
                <div class="space-ten"></div>
            </div>
        </div>


    </div>
</div>

<div class="modal fade product_view" id="product_view">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <a href="#" data-dismiss="modal" class="class pull-right"><span class="glyphicon glyphicon-remove"></span></a>
                <h3 class="modal-title"><?php echo $row['d'];?></h3>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-6 product_img">
                        <img src="http://img.bbystatic.com/BestBuy_US/images/products/5613/5613060_sd.jpg" class="img-responsive">
                    </div>
                    <div class="col-md-6 product_content">
                        <h4>Product Id: <span><?php echo $row['b'];?></span></h4>

                        <p><?php echo $row['c'];?></p>

                        <div class="space-ten"></div>
                        <div class="btn-ground">
                            <button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-shopping-cart"></span>Here Should come  $row['a']</button>
                            <button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-heart"></span>Here Should come $row['b']</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php endif: ?>