0

我想在 PHP 中编辑一行,其中一个字段是一个下拉列表,它将获取为所选行(能力组)设置的值,但问题是所选选项为空,尽管查询有效并且我也可以使用 print_r 打印值。但是当我把它放在表单中时,它什么也没显示。

我以这种形式使用它:

<select  class="edit_competence_group" name="Competence_Group_Edit">
    <?php   
    $r=$this->matchinggroup;
    $Competence_Group=$r['Competence_Group'];
    print_r($this->matchinggroup);
    ?>
    <option selected="selected" value=<?php if (isset ($Competence_Group)) {echo $Competence_Group;}?>></option>
    <?php 
    $arr=$this->distinct_competence_groups;

    foreach ($arr as $row){

        echo "<option value='" .$row['Competence_Group']. "'>" .$row['Competence_Group'] . "</option>";         
    }
    ?>


</select>

获取特定组的查询在一个类中,如下所示:

function editCompetence($Competence_id){
    if(is_numeric($Competence_id) && $Competence_id != 0){
        try{
            $this->query = "UPDATE Competences SET
                            Competence_Group=$this->Competence_Group
                            Competence_Class=$this->Competence_class
                            Competence_Description=$this->Competence_Description    
                            WHERE Competence_ID=$this->Competence_id";
            $tulos = $this->suoritaKysely();
            if(TESTITULOSTUS_LUOKKA){   echo 'Editing Competence with ID : '.$this->Competence_id.'<br/>Tulos: '.$tulos.'<br/>';    }

            if($tulos===false){
                return array('tulos'=>false,'viesti'=>'Competence could not be edited'.'<br />');
            }
            else return array ('tulos'=> true, 'viesti'=>'competence was edited'.'<br/>');

        }catch (Exception $e) {
            return array( 'tulos' => false, 'viesti' => _("tietokantavirhe").' :'.$e->getMessage());

        }
    }
}

我在索引文件中调用该函数:

if(isset($_REQUEST['edit_id'])){
    echo $_GET['edit_id'];
    $oneC=$hr_object->matchingGroup($_GET['edit_id']);
    $page->assign('matchinggroup', $oneC);}
4

1 回答 1

0

尝试这样的事情:

<select  class="edit_competence_group" name="Competence_Group_Edit">
    <?php   
    $r=$this->matchinggroup;
    $Competence_Group=$r['Competence_Group'];
    print_r($this->matchinggroup);
   if (isset ($Competence_Group))
     echo '<option value=" '.$Competence_Group.'" selected >your forgot the name here</option>';

    $arr=$this->distinct_competence_groups;

    foreach ($arr as $row){

        echo "<option value='" .$row['Competence_Group']. "'>" .$row['Competence_Group'] . "</option>";         
    }
    ?>


</select>
于 2013-02-28T09:22:05.283 回答