-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_insert_serie_2.php
41 lines (34 loc) · 1.31 KB
/
script_insert_serie_2.php
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
<?php
set_time_limit(1500);
include_once 'fonctions/accesBD.php';
$link = Connection();
$sql = "SELECT * FROM e_resultat WHERE fk_election=2 ORDER BY nb_inscrits";
$req = mysqli_query($link,$sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysqli_error($link));
$liste_res = array();
$nb = 0;
$nb_res = 1;
$index_res = 0;
$somme_nb_inscrits = 0;
$somme_nb_votants = 0;
$sample_size = 200;
while($res = mysqli_fetch_array($req)){
$somme_nb_inscrits += $res['nb_inscrits'];
$somme_nb_votants += $res['nb_votants'];
if($nb_res%$sample_size == 0){
if(($somme_nb_inscrits/$sample_size)-($somme_nb_votants/$sample_size)){
$liste_res[$index_res]['nb_inscrits_moy'] = $somme_nb_inscrits/$sample_size;
$liste_res[$index_res]['tau_moy'] = log(($somme_nb_votants/$sample_size) / (($somme_nb_inscrits/$sample_size)-($somme_nb_votants/$sample_size)));
$sql_string = "INSERT INTO e_serie (fk_type_serie,x,y) VALUES (2,'%s','%s')";
$sql = sprintf($sql_string,$liste_res[$index_res]['nb_inscrits_moy'],$liste_res[$index_res]['tau_moy']);
mysqli_query($link,$sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysqli_error($link));
$index_res++;
}
$somme_nb_inscrits = 0;
$somme_nb_votants = 0;
}
$nb_res++;
}
echo sizeof($liste_res);
Deconnection($link);
echo "<br />END";
?>