<?php
// ------------------------------------------------------------------------- //
// Combobox avec tous les items d'un champ d'une base, classés et dedoublés //
// ------------------------------------------------------------------------- //
// Auteur: Philippe Genvo //
// Email: phgenvo@free.fr //
// Web: http://www.translucide.com //
// ------------------------------------------------------------------------- //
function trouvemots($table,$champ,$base)
{
$question = "SELECT $champ FROM $table WHERE 1";
$trouve = mysql_db_query ($base,$question);
$i =0;
while ($result = mysql_fetch_array($trouve))
{
if (!empty($result[$champ]))
{
//* le separateur est ici la , : explode(","...;
$toto = explode(",",$result[$champ]);
for ($k=0;$k < count($toto);$k++)
{
$mots[$i+$k] = ltrim($toto[$k]);
}
}
$i=$i+$k;
}
$i=0;
while(list($k,$v)=each($mots))
{
$b[$v]++;
}
$i=0;
while(list($k,$v)=each($b))
{
$motsok[$i] = $k;
$i++;
}
sort($motsok);
return($motsok);
}
// -----------------
// appel du script et realisation de la liste
$mots = trouvemots($table,$champ,$base);
?>
<form method="post" action="monprogramme.php3">
<select name="trouve" >
<option selected value="" > - Selection -
<?php
for ($i=0;$i < count($mots) ; $i++)
{
//* j'evite de traiter des données trop longues
print "\t\t<option> ".(substr($mots$i],0,80))."\n";
}
?>
</select>
<input border="0" src="choisir.gif" name="Envoyer" type="image" >
</form>