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

标签 php html mysql loops modal-dialog

1st 我使用 while 循环用我的数据库数据创建了我的 div。所以它会创建多个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。

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

最佳答案

<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: ?>

关于php - 使用 mysql 和 php 将动态创建的 div 数据发送到 html 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45017728/

相关文章:

php - 国家文化国旗数据库导出?

html - 使用 Flexbox 的固定宽度下拉菜单?

mysql - 使用 CONCAT 和 NULL 值

mysql - 根据当前行和前一行的值填充列 mysql

php - Laravel:创建动态属性

php - 如何在 Laravel 5.7 中限制对数据库的数据输入

php - 在 div 中显示来自另一个网页/IFRAME 脚本的内容

javascript - 复选框如何通过 javascript 触发 html 中的另一个输入元素?

asp.net - 如何使用 Eval 更改 TemplateField 中的颜色

php - 不同类型的 mysql php 请求