模态内的数据信息

时间:2014-03-07 02:29:55

标签: php jquery mysql twitter-bootstrap

我需要在模态中显示DB内的信息,当用户点击每个商品的按钮时,模态显示带有该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>

1 个答案:

答案 0 :(得分:0)

我已经做到了!

只需要将<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>