= à cette date $jour=date("Y-m-d"); /********************************************************************** Try to connect to the MySQL server ***********************************************************************/ @mysql_connect ($serveur, $user, $password) or die ("Erreur : connexion a la base de donnees impossible"); /********************************************************************** Try to select the given database ***********************************************************************/ @mysql_select_db($base) or die ("Erreur : pas de base de donnees ".$base); /**********************************************************************/ // comptage des reservations pour chaque spectacle // compter d'abord le nombre de spectacles $req=mysql_query("SELECT * FROM spectacles WHERE date>='$jour' AND nom='pour qui veut voir' ORDER BY date"); $nbspectacles = mysql_num_rows($req); // pûis parcourir la liste en captant le nombre de res de chaque spectacle $n = 0; while ($row = mysql_fetch_array ($req)) { $date_sql = explode('-', $row["date"]); $date_fr = $date_sql[2]."-".$date_sql[1]."-".$date_sql[0]; $gmaglabel[$n]=$row["nom"]." ".$date_fr; $gmagdata[$n]=$row["nbres"]; //echo $gmaglabel[$n]." ".$gmagdata[$n]."
"; $n++; } mysql_close(); // Calcul du graphe $graphwidth = 800; $graphheight = 500; $graphscale = 2; $graphfont = 5; $gdfont = 5; $labelfont = 3; $image2 = imagecreate($graphwidth, $graphheight); /* definir les couleurs */ // couleur du fond (bleu ciel) $bgcolor = imagecolorallocate($image2, 0xce, 0xfa, 0xfe); // couleur des lignes (ocre) $gdcolor = imagecolorallocate($image2, 0xcc, 0xcc, 0xcc); // couleur du texte echelle de pourcentage (Jaune/or) $titcolor = imagecolorallocate($image2, 0xf2, 0xaa, 0x00); // couleur du texte (noir) $txtcolor = imagecolorallocate($image2, 0x00, 0x00, 0x00); // couleur autre texte (vert fluo) $labelcolor = imagecolorallocate($image2, 0x00, 0xfe, 0x40); /* couleur des rectangles pourcentage couleur de base (vert) */ $barcolor = imagecolorallocate($image2, 0x00, 0xfe, 0x40); /* couleur plus de 25 % (orange) */ $colcolor = imagecolorallocate($image2, 0xec, 0xc6, 0x36); /* couleur plus de 48 % (rouge) */ $topcolor = imagecolorallocate($image2, 0xd0, 0x00, 0x00); // dessiner le graphe : imagefill($image2, 0, 0, $bgcolor); /* ligne verticale */ $gdlabelwidth = imagefontwidth($gdfont)*3 + 1; imageline($image2, $gdlabelwidth, 0, $gdlabelwidth, $graphheight-1, $gdcolor); /* lignes horizontales */ for ($index = 0; $index < $graphheight; $index += $graphheight /10) { imagedashedline($image2, 0, $index, $graphwidth-1, $index, $gdcolor); //if ($index > 30 ) { imagestring($image2, $gdfont, 0, $index, round(($graphheight - $index) / $graphscale), $titcolor); //} } /* ligne du bas */ imageline($image2, 0, $graphheight-1, $graphwidth-1, $graphheight-1, $gdcolor); /* construction des barres */ $barwidth =(($graphwidth-$gdlabelwidth) / $n) - 10; /* dessiner les graphes(rectangles) pourcentage */ /* calcul de la largeur de chaque rectangle */ for ($index = 0; $index < $n; $index++) { /* calcul des coordonnees coin superieur gauche et et inferieur droit */ $bartopX = $gdlabelwidth + (($index+1) * 10) + ($index * $barwidth); $barbottX = $bartopX + $barwidth; $barbottY = $graphheight-1; $bartopY = $barbottY - ($gmagdata[$index] * $graphscale); /* Modifier la couleur du graphe en fonction de sa valeur */ // supérieur ou egale a 78 if ($gmagdata[$index] > $maxres) { $graphcolor = $topcolor; } // superieur a 39 else if ($gmagdata[$index] > ($maxres/2)) { $graphcolor = $colcolor; } else { $graphcolor = $barcolor; } /* dessinner chaque rectangle */ imagefilledrectangle($image2, $bartopX, $bartopY, $barbottX, $barbottY, $graphcolor); $labelX = $bartopX + (($barbottX - $bartopX) / 2) - (imagefontheight($labelfont) / 2); $labelY = $barbottY -10; /* positionner le texte (label) verticalement, correspondant a la valeur de chaque resultat (rectangle) du vote */ imagestringup($image2, $labelfont, $labelX, $labelY, "$gmaglabel[$index] : $gmagdata[$index]", $txtcolor); } // afficher l'image2 header("Content-type: image/png"); imagepng($image2); ?>