具有动态ID的模态弹出窗口

时间:2015-05-01 06:50:34

标签: php jquery twitter-bootstrap

这是我的代码

$sql = "select * from billbook where stcode =? and sem =?";
$query = $mysqli->prepare($sql);
$query->bind_param('si',$stcode, $sem);
$query->execute();
$query->store_result();
$query->bind_result($billno,$billdate,$stcode,$sem,$amount);
$x = 1;
while($query->fetch())
{
?>
    <tr>
        <td align='center'><?php echo $x ?></td>
        <td align='center' id="bno"><a href=""><?php echo $billno ?></a></td>
        <td align='center'><?php echo $billdate?></td>
        <td align='right'><?php echo $amount?>.00</td>
    </tr>
<?php
}
?>

当用户点击&#34; bno &#34;时,我的目的是在Bootstrap的模态对话框弹出窗口中显示帐号的详细信息。处理外部PHP文件中的详细信息后的ID(第二列)。 请帮助。

1 个答案:

答案 0 :(得分:1)

<td align="center" id="bno"><a href="#" data-toggle="modal" data-target="#billno-<?= $billno ?>"><?= $billno ?></a></td>

<?php
// generate a modal per bill
$modals[] = array(
    'billno'                => $billno,
    'modal_id'              => 'billno-'.$billno,
    'title'                 => 'Bill No. '.$billno,
    'message'               => 'Modal body here',
    'dismiss_button_text'   => 'Close'
);
?>

...

<?php foreach ($modals as $modal) : ?>

    <!-- Modal -->
    <div class="modal fade" id="billno-<?= $modal['billno'] ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title"><?= $modal['title'] ?></h4>
                </div>
                <div class="modal-body">
                    <p><?= $modal['message'] ?></p>
                </div>
                <div class="modal-footer">
                    <div class="form-group">
                        <button type="button" class="btn btn-success form-control" data-dismiss="modal"><?= $modal['dismiss_button_text'] ?></button>
                    </div>
                </div>
            </div>
        </div>
    </div>

<?php endforeach; ?>