Fonctions utiles

Préparation pour un champ select
public function prepareSelect2($table, $champId, $champAffiche){
    $sql=" SELECT $champId, $champAffiche FROM $table ";
    $sth = $this->dbh->query($sql);

    $tab1 = array();
    $tab2 = array();
    while($row = $sth->fetch(PDO::FETCH_NUM)){
        $tab1[] = $row[0];
        $tab2[] = $row[1];
    }
    return array_combine($tab1, $tab2);
}
Le champ select
function select2($name, $tab, $default='', $param=''){
        $affich .= '<select name="'.$name.'" id="'.$name.'" '.$param.'>';
        foreach($tab as $id=>$val){
            $selected=($default==$id)?' selected ': '';
            $affich .= '<option value="'.$id.'" '.$selected.'>'.$val.'</option>';
        }
        $affich .= '</select>';
        return $affich;
}