2017-05-19 24 views
0

這裏是所有優惠券表數據與獲取代碼按鈕一起顯示的代碼。我無法獲得發送選定的優惠券ID以打開模式的竅門。她是成功顯示所有數據的代碼。以下是我必須通過優惠券ID的模態代碼。從數據庫傳遞ID以打開模式

代碼完美的作品..

<?php 
$q=mysqli_query($con," SELECT c.* , sc.* , sm.* ,ca.* from store_category sc INNER JOIN store_manufacture sm ON sm.sm_id=sc.store_id INNER JOIN categories ca ON ca.cat_id=sc.cat_id INNER JOIN coupons c on c.c_sc_id=sc.sc_id "); 
while($row1=mysqli_fetch_array($q,MYSQLI_ASSOC)) { 
    $h = strpos($row1['sm_link'],'http'); 
?> 
<div id="popular" class="tab-pane counties-pane active animated fadeIn"> 
<div class="coupon-wrapper row"> 
<div class="coupon-data col-sm-2 text-center"> 
    <div class="savings text-center"> 
    <div> 
    <div class="large"><?php echo $row1['c_name'] ?></div> 
    <div class="type"><?php echo $row1['sm_brand_name'] ?></div> 
    </div> </div> </div> 
    <div class="coupon-contain col-sm-7"> 
    <h4 class="coupon-title"><a href="<?php echo ($h !== FALSE)?$row1['sm_link']:"http://".$row1['sm_link'] ?>" target="_blank"><?php echo $row1['c_description']?></a></h4> 
    <p data-toggle="collapse" data-target="#1">Shop these Shopname deals of the day to save as much...</p> 
    <p id="1" class="collapse">Don't miss out on all the coupon savings.Get you coupon now and save big</p> 
    </div> 
    <div class="button-contain col-sm-3 text-center"> 
    <p class="btn-code" data-toggle="modal" data-target=".couponModal"> 
    <span class="partial-code"><?php echo $row1['c_code'] ?></span> 
    <span class="btn-hover">Get Code</span></p> 
    </div></div> </div> 
     <?php 
      } 
     ?> 

莫代爾這是同一個頁面上。

<?php 
// can't get the query for the selected coupon code to open this modAL 
?> 
    <div class="coupon_modal modal fade couponModal" tabindex="-1" role="dialog"> 
    <div class="modal-dialog modal-lg" role="document"> 
    <div class="modal-content"> 
    <button type="button" class="close" data-dismiss="modal" aria-label="Close"> 
<span aria-hidden="true"><i class="ti-close"></i></span></button> 
<div class="coupon_modal_content"> 
<div class="row"> 
    <div class="col-sm-10 col-sm-offset-1 text-center"> 
    <h2><?php echo $row1['c_name'] ?></h2> 
    <p><?php echo $row1['c_description'] ?></p> 
    </div><div class="row"> 
    <div class="col-sm-12"><h5 class="text-center text-uppercase m-t-20 text-muted">Click below to get your coupon code</h5></div> 
    <div class="col-sm-4 col-sm-offset-4 col-xs-6 col-xs-offset-3"> 
    <a href="#" target="_blank" class="coupon_code alert alert-info"><span class="coupon_icon"> 
    <i class="ti-cut hidden-xs"></i></span> <?php echo $row1['c_code'] ?> </a></div></div> </div></div> 
         <!-- end: Coupon modal content --> 
    </div></div></div> </div> <!-- end: Modall --></div> 
     <?php 
     } 
     ?> 

回答

0

只需將要傳輸的ID附加到優惠券模式名稱即可。

<p class="btn-code" data-toggle="modal" data-target=".couponModal_<?php echo $your_id; ?>"> 

最後,在Modal中,使用下面的代碼。

<div class="coupon_modal modal fade couponModal_<?php echo $your_id; ?>" tabindex="-1" role="dialog"> 

希望這個工程。


由於數據被填充的while環PHP之內,所以你需要在循環中有你的整個模態代碼。

只是爲了澄清,由於您的數據正在從數據庫填充,因此強烈建議您對$your_id進行加密以確保安全。

+0

什麼都沒有發生!它現在不開放模態。 – tabia

+0

我編輯了我的答案,以進一步解釋這一點。爲了能夠捕捉Modal中不同記錄的不同值,您需要有不同的模態。這可以通過在PHP while循環中使用模態代碼並且如前所述添加$ your_id來輕鬆實現。 –

+0

小心使用'class'開模 –

0

對阿赫塔的回答有點修改。我會推薦使用ID

<p class="btn-code" data-toggle="modal" data-target="#couponModal_<?php echo $row1['c_id'] ?>"> 

最後,在Modal中,使用下面的代碼。

<div class="coupon_modal modal fade" id="couponModal_<?php echo $row1['c_id'] ?>" tabindex="-1" role="dialog"> 

//整個代碼

<?php 
$q=mysqli_query($con," SELECT c.* , sc.* , sm.* ,ca.* from store_category sc INNER JOIN store_manufacture sm ON sm.sm_id=sc.store_id INNER JOIN categories ca ON ca.cat_id=sc.cat_id INNER JOIN coupons c on c.c_sc_id=sc.sc_id "); 
while($row1=mysqli_fetch_array($q,MYSQLI_ASSOC)) { 
    $h = strpos($row1['sm_link'],'http'); 
?> 
<p class="btn-code" data-toggle="modal" data-target="#couponModal_<?php echo $row1['c_id'] ?>"> 
<div id="popular" class="tab-pane counties-pane active animated fadeIn"> 
<div class="coupon-wrapper row"> 
<div class="coupon-data col-sm-2 text-center"> 
    <div class="savings text-center"> 
    <div> 
    <div class="large"><?php echo $row1['c_name'] ?></div> 
    <div class="type"><?php echo $row1['sm_brand_name'] ?></div> 
    </div> </div> </div> 
    <div class="coupon-contain col-sm-7"> 
    <h4 class="coupon-title"><a href="<?php echo ($h !== FALSE)?$row1['sm_link']:"http://".$row1['sm_link'] ?>" target="_blank"><?php echo $row1['c_description']?></a></h4> 
    <p data-toggle="collapse" data-target="#1">Shop these Shopname deals of the day to save as much...</p> 
    <p id="1" class="collapse">Don't miss out on all the coupon savings.Get you coupon now and save big</p> 
    </div> 
    <div class="button-contain col-sm-3 text-center"> 
    <p class="btn-code" data-toggle="modal" data-target=".couponModal"> 
    <span class="partial-code"><?php echo $row1['c_code'] ?></span> 
    <span class="btn-hover">Get Code</span></p> 
    </div></div> </div> 

<div class="coupon_modal modal fade couponModal" tabindex="-1" role="dialog" id="couponModal_<?php echo $row1['c_id'] ?>"> 
    <div class="modal-dialog modal-lg" role="document"> 
    <div class="modal-content"> 
    <button type="button" class="close" data-dismiss="modal" aria-label="Close"> 
<span aria-hidden="true"><i class="ti-close"></i></span></button> 
<div class="coupon_modal_content"> 
<div class="row"> 
    <div class="col-sm-10 col-sm-offset-1 text-center"> 
    <h2><?php echo $row1['c_name'] ?></h2> 
    <p><?php echo $row1['c_description'] ?></p> 
    </div><div class="row"> 
    <div class="col-sm-12"><h5 class="text-center text-uppercase m-t-20 text-muted">Click below to get your coupon code</h5></div> 
    <div class="col-sm-4 col-sm-offset-4 col-xs-6 col-xs-offset-3"> 
    <a href="#" target="_blank" class="coupon_code alert alert-info"><span class="coupon_icon"> 
    <i class="ti-cut hidden-xs"></i></span> <?php echo $row1['c_code'] ?> </a></div></div> </div></div> 
         <!-- end: Coupon modal content --> 
    </div></div></div> </div> <!-- end: Modall --></div> 
     <?php 
      } 
     ?> 
+0

這一個正在工作,但它是作爲褪色屏幕打開模式。 – tabia

+0

等等lemme發佈整個代碼 –

+0

這一個是爲我工作,但模式顯示褪色仍然 – tabia

相關問題