moyenne journalière MySQL
le 03/12/2007 à 21:56
raphlight
Déconnecté
http://raphlight.free.fr/miniville2/
Bonjour,
j'ai une base MySQL contenant un certain nombre d'enregistrements.
Cette base est en marche depuis le 22 Août 2007.
J'aimerais que MySQL divise le nombre d'enregistrements par le nombre de jours écoulés depuis le 22 Août 2007 afin de calculer la moyenne journalière d'enregistrements pour ensuite l'afficher sur une page du site.
Comment faire ? Je n'ai aucune notion en "calcul MySQL" :S
Merci d'avance
Raphlight
le 03/12/2007 à 22:10
LA GLOBULE
Déconnecté
111 111 111 x 111 111 111 = 12 345 678 987 654 321
Pourquoi ne pas faire ce calcul en PHP ? Ça soulagerait ton MySQL.
le 04/12/2007 à 22:43
raphlight
Déconnecté
http://raphlight.free.fr/miniville2/
je suis d'accord mais je ne sais pas non plus comment m'y prendre :S
le 04/12/2007 à 23:56
LA GLOBULE
Déconnecté
111 111 111 x 111 111 111 = 12 345 678 987 654 321
Ben c'est une simple règle de trois.
Voici un exemple (je pars du principe que tu sais compter ton nombre total d'enregistrement) :
<?php
$nb_enregistrement = 250 ; $time_start = mktime ( 0 , 0 , 0 , 8 , 22 , 2007 ) ; $time_end = time ( ) ; echo round ( $nb_enregistrement / ( ( $time_end - $time_start ) / ( 60 * 60 * 24 ) ) , 2 ) ; ?>
le 05/12/2007 à 17:27
raphlight
Déconnecté
http://raphlight.free.fr/miniville2/
Pour compter et afficher le nombre d'enregistrements, j'utilise ce bout de code :
Donc, si j'adapte ton code, ca donnera ca ?
<?php
$link = mysql_connect ( "******" , "******" , "******" ) ; mysql_select_db ( "database" , $link ) ; $res = mysql_query ( "SELECT COUNT(1) FROM la-table-contenant-les-enregistrements" , $link ) ; $row = mysql_fetch_row ( $res ) ; $time_start = mktime ( 0 , 0 , 0 , 8 , 22 , 2007 ) ; $time_end = time ( ) ; echo round ( $row [ 0 ] / ( ( $time_end - $time_start ) / ( 60 * 60 * 24 ) ) , 2 ) ; mysql_close ( ) ; ?>
Merci d'avance
le 06/12/2007 à 23:19
raphlight
Déconnecté
http://raphlight.free.fr/miniville2/
:up:
le 06/12/2007 à 23:55
LA GLOBULE
Déconnecté
111 111 111 x 111 111 111 = 12 345 678 987 654 321
As tu testé ?
le 07/12/2007 à 13:09
raphlight
Déconnecté
http://raphlight.free.fr/miniville2/
Oui, je viens de le faire...
J'avais déjà testé mais ca me mettait 13.88 alors que j'ai plus de 20.000 enregistrements.
En fait, c'était juste car je m'étais trompé de table ^^
Donc merci beaucoup la globule, maintenant ca fonctionne, j'ai 204.07 et ca correspond à ce que j'ai trouvé en calculant manuellement ;)
Mais peut-on donner le résultat à l'unité ? par exemple, au lieu d'avoir 204.07 on aura 204 et au lieu de 235.95 on aura 236...
raphlight
le 07/12/2007 à 22:43
i M@N
Déconnecté
One Love, One Heart, One Unity.
Hello.
Ah wé ... comme si on utilisait la fonction
round .
@+...
Accès rapide :
PHP / MySQL
HTML / CSS
Javascript
Autres technologies
Le site
Les 3H du PHP
Le bar
Script / Production personnelle
Remonter