2017-05-19 6 views
0

Hier ist Code, in dem alle Coupon-Tabellendaten mit Get-Code-Schaltfläche angezeigt werden. Ich kann nicht den Trick bekommen, die ausgewählte Coupon-ID zu senden, um ein Modal zu öffnen. Sie ist der Code, in dem alle Daten erfolgreich angezeigt werden. Unten ist der Code für Modal, in dem ich die Coupon-ID übergeben muss.ID von Datenbank an Modal übergeben

Code perfekt funktioniert ..

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

Modal Es ist auf der gleichen Seite.

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

Antwort

0

Fügen Sie einfach die ID, die Sie übertragen möchten, an den Coupon Modal Name an.

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

Schließlich, in der Modal, verwenden Sie den folgenden Code.

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

Ich hoffe, das funktioniert.


Da Ihre Daten innerhalb einer while Schleife von PHP bevölkert werden, so müssen Sie Ihren gesamten Modal-Code innerhalb der Schleife haben.

Nur um zu verdeutlichen, da Ihre Daten aus der DB gefüllt werden, wird dringend empfohlen, $your_id verschlüsselt zu haben, um es zu sichern.

+0

nichts passiert !! Es öffnet sich jetzt nicht modal. – tabia

+0

Ich habe meine Antwort bearbeitet, um dies weiter zu erklären. Um die verschiedenen Werte verschiedener Datensätze in Modal erfassen zu können, müssen Sie verschiedene Modalitäten haben. Dies kann leicht erreicht werden, indem Sie Ihren modalen Code innerhalb der PHP while-Schleife haben und das $ your_id angehängt haben, wie zuvor erklärt. –

+0

Vorsicht bei der Verwendung von 'class' zum Öffnen von Modal –

0

Eine kleine Änderung zu Akhtars Antwort. Ich würde empfehlen, ID

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

schließlich im Modal, verwenden Sie den folgenden Code verwenden.

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

// Vollständige Code

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

Dieser funktioniert, aber es öffnet Modal als verblasster Bildschirm. – tabia

+0

Warte Lemme post den ganzen Code –

+0

dieser arbeitet für mich, aber das Modal zeigt verblasst immer noch – tabia

Verwandte Themen