如何获取php变量中select标签的选项值$ r [' id_usr']

时间:2015-05-18 11:25:44

标签: php jquery html

我的问题是我需要获取选择标记的选项值 $ r [&#39; usr_id&#39;] 当submmited在 php <中使用该值时/ strong>查询

这是我的代码:

 <div class="form-group">
 <label class="col-md-2 col-xs-12 control-label">Piloté Par</label>
 <div class="col-md-4 col-xs-12">  
    <?php
    // LOGIN TO DATABASE SCRIPT WRITTEN FOR MYSQLI
    $mysqli = new mysqli("localhost", "root", "", "schb");
    if ($mysqli->connect_errno) {
        echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
    }
    // END OF LOGIN TO DB SCRIPT

    $query_ak = "SELECT id_usr, nom_usr, pnom_usr FROM user WHERE role='Pilote processus' AND id_usr NOT IN (SELECT pilot_id FROM processus)";
    $result = $mysqli->query($query_ak);
    ?>
    <select class="form-control select" name="slctpilot" >
        <?php
        while ($r = mysqli_fetch_assoc($result)) {
            echo '<option value="' . $r['id_usr'] . '">' . $r['nom_usr'] . ' ' . $r['pnom_usr'] . '</option>';
        }
        ?>
    </select>
</div>

3 个答案:

答案 0 :(得分:1)

表单提交(发布)后,将其存储在变量 -

$userId = $_POST['slctpilot'];

如果value="' . $r['id_usr'] . '" - &gt; value='23' $userId将保留23

答案 1 :(得分:0)

试试这个:

 echo '<option value="<?php echo $r['id_usr']; ?>" <?php $r['nom_usr'].$r['pnom_usr'];?></option>';

答案 2 :(得分:0)

您可以使用以下代码获取选择字段的值...

    [Browsable(false)]
    public Activity Body { get; set; }

    protected override void Execute(NativeActivityContext context)
    {
        ActivityInstance res = context.ScheduleActivity(Body, new CompletionCallback(OnExecuteComplete), OnFaulted);
    }

    private void OnFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
    {
        throw new Exception(propagatedException.Message);
    }