1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| Class outils
{
// Fonction qui affiche un champs de table indexé dans une liste déroulante,
// une connection au serveur et à la base de données est exigée
function combo_liste($table,$champ,$index,$valeur,$affiche="")
{
$this->table=$table;
$this->champ=$champ;
$this->index=$index;
$this->valeur=$valeur;
$this->affiche=$affiche;
$sql="Select * from ".$this->table." order by ".$this->index;
if($resultat=mysql_query($sql))
{
if($nbligne=mysql_numrows($resultat))
{
$i=0;
while ($i < $nbligne)
{
$option = mysql_result($resultat,$i,$this->champ);
if ($this->affiche!="")
{
$val_affiche = mysql_result($resultat,$i,$this->affiche);
$value = $val_affiche;
}
else
{
$value=$option;
}
if($this->valeur!=$value)
{
$liste_resultat .= '<OPTION value="'.$value.'">'.$option.'</OPTION>';
}
else
{
$liste_resultat .= '<OPTION selected value="'.$value.'">'.$option.'</OPTION>';
}
$i++;
}
return $liste_resultat;
}
}
}
} |
Partager