1. Home
  2. Computing & Technology
  3. PHP / MySQL

Simple PHP & MySQL Poll

By , About.com Guide

5 of 5

Using GD Library

<?php
$slide = $one + $two;
header('Content-type: image/png');
$handle = imagecreate(100, 100);
$background = imagecolorallocate($handle, 255, 255, 255);
$red = imagecolorallocate($handle, 255, 0, 0);
$green = imagecolorallocate($handle, 0, 255, 0);
$blue = imagecolorallocate($handle, 0, 0, 255);
$darkred = imagecolorallocate($handle, 150, 0, 0);
$darkblue = imagecolorallocate($handle, 0, 0, 150);
$darkgreen = imagecolorallocate($handle, 0, 150, 0);

// 3D look
for ($i = 60; $i > 50; $i--)
{
imagefilledarc($handle, 50, $i, 100, 50, 0, $one, $darkred, IMG_ARC_PIE);
imagefilledarc($handle, 50, $i, 100, 50, $one, $slide , $darkblue, IMG_ARC_PIE);
imagefilledarc($handle, 50, $i, 100, 50, $slide, 360 , $darkgreen, IMG_ARC_PIE);
}
imagefilledarc($handle, 50, 50, 100, 50, 0, $one , $red, IMG_ARC_PIE);
imagefilledarc($handle, 50, 50, 100, 50, $one, $slide , $blue, IMG_ARC_PIE);
imagefilledarc($handle, 50, 50, 100, 50, $slide, 360 , $green, IMG_ARC_PIE);
imagepng($handle);
?>
In our script we called vote_pie.php to display the pie chart of our results. The above code should be placed in the vote_pie.php file. Basically what this does is draw arcs to create a pie. We passed the variables it needed in the link from our main script. To better understand this code, you should read our GD tutorial that covers arcs and pies.
Explore PHP / MySQL
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Graphics- GD Library
  5. GD Library Poll - Poll Results Graphical - GD Library Pie Chart Poll

©2009 About.com, a part of The New York Times Company.

All rights reserved.