将php值传递给弹出窗口

时间:2017-05-18 03:05:37

标签: javascript jquery

我有一张桌子:

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

<button type="button" id="choose-template">Start Evaluation</button>将打开弹出窗口以选择模板。的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");
            }
        });
    });                   
});

弹出窗口,我想获得username and id并将其传递给ajax:

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

问题是我总是得到表中最新行的用户$username, staff_id。我怎样才能准确传递我需要的值?

1 个答案:

答案 0 :(得分:0)

首先,在While循环之前预先定义这些变量:

ThisWorkbook.FollowHyperlink Address:=Target.Value 

在While循环中,您需要创建另一个数组,您可以使用它来填充弹出式div。这样做:

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

然后,对于div部分,您需要做的是重新填充它们(在While循环之外执行此操作):

$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'];