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
| <?php
require 'le_script_de_connexion_ki_va_bien.inc.php';
$sql='SELECT id,nom,prenom,sexe FROM A';
// éventuellement ORDER BY nom,prenom [ASC ou DESC] ou autre chose
$result=mysql_query($sql) or die($sql.'<br />'.mysql_error());
$machos=array();$hembras=array();$hybrides=array();
while($ligne=mysql_fetch_assoc($result)){
switch($ligne['sexe']){
case 'F' :
$hembras[]=array('id'=>$ligne[id],
'nom'=>$ligne['nom'],
'prenom'=>$ligne['prenom']);
break;
case 'M' :
$machos[]=array('id'=>$ligne[id],
'nom'=>$ligne['nom'],
'prenom'=>$ligne['prenom']);
break;
otherwise :
//penser aux éventuels sexe IS NULL, non ?
$hybrides[]=array('id'=>$ligne[id],
'nom'=>$ligne['nom'],
'prenom'=>$ligne['prenom']);
} //end switch
$liste=array();
$sexe=0;
while((count($machos)+count($hembras))>0){
if($sexe==0 && count($hembras) > 0){
$liste[]=$hembras[0];
array_splice($hembras,0);
}
elseif(count($machos) >0){
$liste[]=$machos[0];
array_splice($machos,0);
}
$sexe++%2;
} //end while
var_dump($liste);
var_dump($hybrides);
?> |
Partager