Valid XHTML    Valid CSS2    

Listing du fichier sen_ronfle.php

 

00001     <?php
00002     
include("../std.php") ;
00003     
debutPage
("L3SEN Table ronfle","strict") ;
00004     
debutSection() ;
00005     
h1
("CALCULS DANS LA TABLE RONFLE ") ;
00006     
00007     
p
("grouge droite") ;
00008     echo
"gilles.hunault@univ-angers.fr" ;
00009     
finp() ;
00010     
00011     
# connexion à la base statdata sur forge avec l'utilisateur anonymous
00012     
00013     
$cnx
= @mysql_connect("localhost","anonymous","anonymous") or die("problème de connexion") ;
00014     
$dbz
= mysql_select_db("statdata") or die ("problème de base de données") ;
00015     
00016     
h2
("Nombre d'hommes") ;
00017     
00018     
$req
= " SELECT COUNT(*) FROM ronfle WHERE sexe=0 " ;
00019     
$res
= mysql_query($req) ;
00020     
$tabr
= mysql_fetch_array($res) ;
00021     
$nbhom
= $tabr["COUNT(*)"] ;
00022     
00023     
# echo "Requ&ecirc;te : ".em($req) ;
00024      # br() ;
00025     
echo
em(" La table RONFLE comporte $nbhom hommes.") ;
00026     
00027     
h2
("Nombre d'hommes qui ronflent et qui fument") ;
00028     
00029     
$req
= " SELECT COUNT(*) FROM ronfle WHERE sexe=0 AND ronfle=1 AND taba=1" ;
00030     
$res
= mysql_query($req) ;
00031     
$tabr
= mysql_fetch_array($res) ;
00032     
$nbhrf
= $tabr["COUNT(*)"] ;
00033     
00034     
# br() ;
00035     
echo
em(" La table RONFLE comporte $nbhrf hommes qui ronflent et qui fument.") ;
00036     
00037     
h2
("Pourcentage d'hommes qui ronflent et qui fument par rapport au nombre d'hommes via SQL") ;
00038     
00039     
$champ
= "pcthrf" ;
00040     
$req
= " SELECT 100*(COUNT(*)/$nbhom) AS $champ FROM ronfle WHERE sexe=0 AND ronfle=1 AND taba=1" ;
00041     
$res
= mysql_query($req) ;
00042     
$tabr
= mysql_fetch_array($res) ;
00043     
$pct
= $tabr[$champ] ;
00044     
00045      echo
"Requ&ecirc;te : "
.em("$req ;") ;
00046     
br() ;
00047      echo
em
(" Ce pourcentage via SQL est $pct.") ;
00048     
00049     
h2
("Pourcentage d'hommes qui ronflent et fument par rapport au nombre d'hommes via PHP") ;
00050     
00051     
$pct
= 100 * ($nbhrf/$nbhom) ;
00052      echo
em
(" Ce pourcentage via PHP est $pct.") ;
00053     
00054     
h2
("Pourcentage arrondi par SQL ") ;
00055     
00056     
$champ
= "pcthrf" ;
00057     
$req
= " SELECT ROUND(100*(COUNT(*)/$nbhom)) AS $champ FROM ronfle WHERE sexe=0 AND ronfle=1 AND taba=1" ;
00058     
$res
= mysql_query($req) ;
00059     
$tabr
= mysql_fetch_array($res) ;
00060     
$pctarr
= $tabr[$champ] ;
00061     
00062      echo
em
(" Ce pourcentage arrondi via SQL est $pctarr.") ;
00063     
00064     
h2
("Pourcentage arrondi par PHP ") ;
00065     
00066     
$pct1
= round (100 * ($nbhrf/$nbhom) , 0 ) ;
00067      echo
em
(" Ce pourcentage arrondi via PHP est $pct1 %(version 1).") ;
00068     
00069     
br() ;
00070     
00071     
$pct2
= sprintf("%4.0f",100 * ($nbhrf/$nbhom) , 0 ) ;
00072      echo
em
(" Ce pourcentage arrondi via PHP est $pct2 % (version 2).") ;
00073     
00074     
h2
("Listage des 10 plus jeunes femmes qui ronflent ") ;
00075     
00076     
$nbf
= 0 ;
00077     
$champ
= "pcthrf" ;
00078     
$req
= " SELECT IDEN, AGE FROM ronfle WHERE sexe=1 AND ronfle=1 ORDER BY age LIMIT 10" ;
00079     
$res
= mysql_query($req) ;
00080      while (
$tabr
= mysql_fetch_array($res)) {
00081     
$nbf++ ;
00082     
$iden
= $tabr["IDEN"] ;
00083     
$age
= $tabr["AGE"] ;
00084      echo
"
$nbf ID : $iden AGE = $age \n" ;
00085     
br() ;
00086      } ;
# fin de tant que
00087     
00088     
h2
("Listage en tableau des 10 plus jeunes femmes qui ronflent ") ;
00089     
00090     
$nbf
= 0 ;
00091     
$champ
= "pcthrf" ;
00092     
$req
= " SELECT IDEN, AGE FROM ronfle WHERE sexe=1 AND ronfle=1 ORDER BY age LIMIT 10" ;
00093     
$res
= mysql_query($req) ;
00094     
table
(1,5,"collapse") ;
00095     
tr() ;
00096     
th
() ; echo " &nbsp; NUM &nbsp; " ; finth() ;
00097     
th
() ; echo "IDEN" ; finth() ;
00098     
th
() ; echo "AGE" ; finth() ;
00099     
fintr() ;
00100      while (
$tabr
= mysql_fetch_array($res)) {
00101     
$nbf++ ;
00102     
$iden
= $tabr["IDEN"] ;
00103     
$age
= $tabr["AGE"] ;
00104     
tr() ;
00105     
td
("R") ; echo $nbf ; fintd() ;
00106     
td
() ; echo $iden ; fintd() ;
00107     
td
() ; echo $age ; fintd() ;
00108     
fintr() ;
00109      } ;
# fin de tant que
00110     
fintable() ; ;
00111     
00112     
mysql_close
($cnx) ;
00113     
00114     
#########################################
00115     
00116     
p() ;
00117     echo
href
("montresource.php?nomfic=sen_ronfle.php","Code-source de la page") ;
00118     
finp() ;
00119     
00120     
00121     
finSection() ;
00122     
finPage() ;
00123     
?>

Pour ne pas voir les numéros de ligne, ajoutez &nl=non à la suite du nom du fichier.

 

 

retour gH    Retour à la page principale de   (gH)