php - 模态内部的数据信息

标签 php jquery mysql twitter-bootstrap

我需要显示模式内数据库中的信息,当用户单击每个优惠的按钮时,模式会显示具有该 id 的优惠...问题是模式信息为空...所以如何捕获 id 以将正确的数据显示到模式中?

这是报价:

<?php if($spa_style == basico) { echo '
    <div class="row">';
            $sql = "SELECT id_oferta, oferta_titulo, oferta_subtitulo, oferta_mensaje, oferta_precio, estado, oferta_foto, style, cupon, popular FROM SPA_OFERTAS WHERE estado = 'activado' ORDER BY id_oferta DESC LIMIT 4";
            $result = $conn->query($sql);
            while($row = $result->fetch(PDO::FETCH_ASSOC)){
  if (!empty($id_oferta)) { echo '
        <div class="span3" id"'.$row["id_oferta"].'">
            <div class="tile '.$row["popular"].'">
                <div>
                    <img src="img/ofertas/'.$row["oferta_foto"].'" alt="'.$row["oferta_titulo"].'" class="img-rounded img-left" style="width:70px; height:70px;" />
                </div>
                <span>'.$row["oferta_titulo"].'</span>
                <h6><small>'.$row["oferta_subtitulo"].'</small></h6>
                <p>'.$row["oferta_mensaje"].'</p>';
                if($row["cupon"] == si) {  echo '<h5><div class="intro-icon-disc"><a href="#spaferta" data-id="'.$row['id_oferta'].'" data-toggle="modal" role="button" class="open-SpaOferta btn btn-info"><b>$'.$row["oferta_precio"].'</b></a></div></h5>'; } 
else if($row["cupon"] == no) { echo '<br />'; } echo '
            </div>
            <div class="pad25"></div>
        </div>'; }  } echo '
    </div>'; } 
?>

这里是模态:

<?php 
    require_once('connection.php');
    $query = "SELECT id_oferta, oferta_titulo, oferta_subtitulo, oferta_mensaje, oferta_precio, oferta_foto FROM SPA_OFERTAS WHERE id_oferta = ?";
    $stmt = $conn->prepare( $query );
    $stmt->bindParam(1, $_REQUEST['id_oferta']);    
    $stmt->execute();
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    $id_oferta = $row['id_oferta'];
    $oferta_titulo = $row['oferta_titulo'];
    $oferta_subtitulo = $row['oferta_subtitulo'];
    $oferta_mensaje = $row['oferta_mensaje'];
    $oferta_precio = $row['oferta_precio'];
    $oferta_foto = $row['oferta_foto'];
 ?>
<div id="spaferta" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <a class="close" data-dismiss="modal"><i class="fa fa-times"></i></a>
        <h3>Cup&oacute;n para : <?php echo $oferta_titulo; ?></h3>
    </div>
    <div class="modal-body">
        <div id="message2"></div><br /><div id="Info_spa"></div>
        <form method="post" action="includes/spa_cupon.php" name="spaform" id="spaform">
            <div class="row-fluid grid">
                <div class="span6">
                    <label for="nombres" accesskey="U"><span class="required">*</span> <b>Nombres : </b></label><input type="text" class="input-block-level" id="nombres" name="nombres" />
                </div>
                <div class="span4">
                    <label for="dui" accesskey="P"><span class="required">*</span> <b>DUI : </b></label><input type="text" class="input-block-level" id="spa_dui" name="dui" />
                </div>
            </div>
            <div class="row-fluid grid">
                <div class="span6">
                    <label for="corelectronico" accesskey="E"><span class="required">*</span> <b>Correo : </b></label><input type="email" class="input-block-level" id="corelectronico" name="corelectronico" />
                </div>
                <div class="span4">
                    <label for="tele" accesskey="P"><span class="required">*</span> <b>Tel&eacute;fono/Celular : </b></label><input type="text" class="input-block-level" id="tele" name="tele" />
                </div>
            </div>
            <div class="row-fluid grid">
                <input type="hidden" id="of_titulo" name="of_titulo" type="text" value="<?php echo $oferta_titulo; ?>" />
                <input type="hidden" id="of_stitulo" name="of_stitulo" type="text" value="<?php echo $oferta_subtitulo; ?>" />
                <input type="hidden" id="of_mensaje" name="of_mensaje" type="text" value="<?php echo $oferta_mensaje; ?>" />
                <input type="hidden" id="of_precio" name="of_precio" type="text" value="<?php echo $oferta_precio; ?>" />
                <input type="hidden" id="of_foto" name="of_foto" type="text" value="<?php echo $oferta_foto; ?>" />
                <p><span class="required">*</span> Eres humano?</p>
                <label for="verify2" accesskey="V">&nbsp;&nbsp;&nbsp;7 - 5 =</label>
                <input name="verify2" type="text" id="verify2" size="4" value="" style="width: 30px;" /><br /><br />
                <input type="submit" class="btn btn-primary submit" id="submit2" value="Grabar Cup&oacute;n" />
            </div>
        </form>
    </div>
    <div class="modal-footer">
        <button class="btn btn-danger" data-dismiss="modal">
            Cerrar
        </button>
    </div>
</div>

最佳答案

我已经做到了!

只需更改 <a href (在我的情况下...在你的情况下,你需要更改数据的 url 和 id),因为我现在使用 ajax 模式:

<a href="spa_oferta.php?id_oferta='.$row["id_oferta"].'" data-toggle="modal" class="cp-btn"><span>CUP&Oacute;N</span></a>

并在模态中删除模态开头的这部分:

<div id="spaferta" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

当然还有模态末尾的关闭 div:

</div>

关于php - 模态内部的数据信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22240312/

相关文章:

PHP MySQL 查询在结果中显示错误的日期时间

php - 如何从时间戳获取日期范围?

mysql - MYSQL中按类别分组的每个财政年度的期初和期末余额之和

php - mysql_query() 期望参数为 mysqli/string

php - 如何解决 Cron 作业运行错误

javascript - Javascript 中最常见的计算能力浪费是什么?

php - php网站的国际化

php - 随时随地更改数据库名称 php

javascript - 如何在嵌套 div 上使用 .click

javascript - 制作div,从左对齐开始,增长到窗口的宽度然后缩小并右对齐