值不会显示在下拉列表中

时间:2013-02-28 09:12:02

标签: php html mysql

我想在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);}

1 个答案:

答案 0 :(得分: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>