2017-05-18 2 views
0

Ich habe eine Tabelle:Pässe php Wert um Pop-up-Fenster

<div class="users"> 
<?php 
//$id = $_SESSION['staff_id']; 

$dateResult = getQuarter($id); 
$count1 = 0; 
if (mysqli_num_rows($dateResult) > 0) 
{ 
?>     
    <table id="one-column-emphasis" > 
    <colgroup> 
     <col class="oce-first" /> 
    </colgroup>     
    <thead> 
     <tr> 
     <th>Username</th> 
     <th>1st Quarter</th> 
     <th>2nd Quarter</th> 
     <th>3rd Quarter</th> 
     <th>4th Quarter</th> 
     </tr> 
    </thead> 
    <?php 
    while($row = mysqli_fetch_array($dateResult)) 
    { 
      $staff_id = $row['staff_id']; 
      $username = $row['username']; 
      $date1 = $row['date1']; 
      $date2 = $row['date2']; 
      $date3 = $row['date3']; 
      $date4 = $row['date4']; 
      $fb_date1 = $row['fdate1']; 
      $fb_date2 = $row['fdate2']; 
      $fb_date3 = $row['fdate3']; 
      $fb_date4 = $row['fdate4']; 
    ?> 
     <tbody> 
      <tr> 
      <td><?php echo $username ?></td>   
      <td> 
       <?php 
       if($date1 == NULL) 
       { echo '<button type="button" id="choose-template">Start Evaluation</button>'; } 
       else 
       { echo "Ev.Date: ". $date1 ."<br/> Fb.Date: ". $fb_date1. ""; } 
       ?> 
      </td>     
      <td> 
       <?php 
       if($date1 != NULL && $date2 ==NULL) 
       { echo '<button type="button" id="choose-template">Start Evaluation</button>'; } 
       else if ($date2 != NULL) 
       { echo "Ev.Date: ". $date2 ."<br/> Fb.Date: ". $fb_date2. ""; } 
       ?> 
      </td> 
      <td> 
       <?php 
       if($date2 != NULL && $date3 ==NULL) 
       { echo '<button type="button" id="choose-template">Start Evaluation</button>'; } 
       else if ($date3 != NULL) 
       { echo "Ev.Date: ". $date3 ."<br/> Fb.Date: ". $fb_date3. ""; } 
       ?> 
      </td> 
      <td> 
       <?php 
       if($date3 != NULL && $date4 ==NULL) 
       { echo '<button type="button" id="choose-template">Start Evaluation</button>'; } 
       else if ($date4 != NULL) 
       { echo "Ev.Date: ". $date4 ."<br/> Fb.Date: ". $fb_date4. ""; } 
       ?> 
      </td> 
      </tr> 
     </tbody> 
    <?php 
    $count1++; 
    } 
} else { 
     echo "<h2>No Data to Display</h2>"; 
    } 
?>     
</table> 
</div> 

Wo <button type="button" id="choose-template">Start Evaluation</button> für die Wahl Vorlage Pop-up-Fenster geöffnet. javascript:

$(function() { 
    dialog2 = $("#template-form").dialog({ 
     autoOpen: false, 
     height: 80, 
     width: 445, 
     modal: true, 
     close: function() { 
     } 
    });   
    $(document).on('click', '#choose-template', function(){ 
     dialog2.dialog("open"); 
    });   

    $(document).on('click', '.quest', function(){ 
     var personal = $(this).val(); 
     $.ajax({ 
      url: "comAssessment/evaluation.php", 
      method: "POST", 
      data: {personal: personal}, 
      dataType:"text", 
      success: function (data) { 
       $('.users').hide(); 
       $('#result').html(data); 
       dialog2.dialog("close"); 
      } 
     }); 
    });     
}); 

Und Popup-Fenster, wo ich will username and id bekommen und an dem Ajax-Pass:

<div id="template-form" title="Choose Questionnaire Template"> 
    <button type='button' class='quest' value='<?php echo "1|".$username."|".$staff_id ?>'><?php echo "1|".$username."|".$staff_id ?></button> 
    <button type='button' class='quest' value='<?php echo "2|".$username."|".$staff_id ?>'><?php echo "1|".$username."|".$staff_id ?></button> 
    <button type='button' class='quest' value='<?php echo "3|".$username."|".$staff_id ?>'><?php echo "1|".$username."|".$staff_id ?></button> 
</div> 

Problem ist ich $username, staff_id der letzten Zeile in der Tabelle immer Benutzer erhalten. Wie kann ich genau die Werte weitergeben, die ich brauche?

Antwort

0

Zuerst diese Variablen vor der While-Schleife vordefinieren:

$username_array = array(); 
$staff_id_array = array(); 
$index = 0; 

Innerhalb Ihrer While-Schleife, würden Sie ein anderes Array vornehmen müssen, von denen Sie verwenden können Sie Ihre Pop-up div aufzufüllen. Tun Sie es als solche:

$staff_id = $row['staff_id']; 
$username = $row['username']; 
$staff_id_array[$index] = $staff_id; 
$username_array[$index] = $username; 
$index++; 
$date1 = $row['date1']; 
$date2 = $row['date2']; 
$date3 = $row['date3']; 
$date4 = $row['date4']; 
$fb_date1 = $row['fdate1']; 
$fb_date2 = $row['fdate2']; 
$fb_date3 = $row['fdate3']; 
$fb_date4 = $row['fdate4']; 

Dann wird für die div Teil, was man braucht, ist, sie zu tun repopulate (tun dies außerhalb der While-Schleife):

<div id="template-form" title="Choose Questionnaire Template"> 
    <?php for($i=0; $i<count($staff_id_array); $i++){ ?> 
     <button type='button' class='quest' value='<?php echo "1|".$username_array[$i]."|".$staff_id_array[$i] ?>'><?php echo "1|".$username_array[$i]."|".$staff_id_array[$i] ?></button> 
    <?php } ?> 
</div> 
+0

scheint nicht zu funktionieren. Jetzt weist er jeder Zeile in der Tabelle den Benutzernamen und die ID der ersten Zeile zu. –

+0

Entschuldigung, da ich deine Codes zuerst nicht richtig gesehen habe, habe ich meine Antwort aktualisiert. – popdroid

Verwandte Themen