// Connects to your Database
mysql_connect("your_server", "your_login", "your_pass") or die(mysql_error());
mysql_select_db("your_database") or die(mysql_error());
//Name of our cookie
$cookie = "Voted";
//A function to display our results - this refrences vote_pie.php which we will also make
function pie ()
{
$data = mysql_query("SELECT * FROM votes")
or die(mysql_error());
$result = mysql_fetch_array( $data );
$total = $result[first] + $result[sec] + $result[third];
$one = round (360 * $result[first] / $total);
$two = round (360 * $result[sec] / $total);
$per1 = round ($result[first] / $total * 100);
$per2 = round ($result[sec] / $total * 100);
$per3 = round ($result[third] / $total * 100);
echo "<img src=vote_pie.php?one=".$one."&two=".$two."><br>";
Echo "<font color=ff0000>FIRST</font> = $result[first] votes, $per1 %<br>
<font color=0000ff>SECOND </font> = $result[sec] votes, $per2 %<br>
<font color=00ff00>THIRD </font> = $result[third] votes, $per3 %<br>";
}
We start out or script with the information we need to
connect to our database. We then name our
cookie, and
define a function called
pie. In our
pie function we retrieve the data from our database. We also preform a few calculations that help us display the results in a user friendly way, such as the percentage each vote has, and how many degrees out of 360 that percentage makes up. We reference vote_pie.php which we will create later in the tutorial.