$pollquery = mysql_query("SELECT * FROM poll");
$numvotes = mysql_num_rows($pollquery);
$xval = 30;
$barwidth = floor(300/$numoptions);
$xvalis the value for the x position of the left-most side of the graph. This value will be manipulated later, but for now, it will be set to 30 (the y-axis's distance from the left hand side of the image, plus 5 pixels for some breathing space). $barwidth determines how wide each bar should be. The 300 used is simply 360 (the length of the x-axis) minus 60 for some more breathing space. This is then divided by the number of vote options. As you may have noticed, a lot of the original values and measurements from the image have been changed to account for "breathing space." This is my term for the space between the bars so that the graph doesn't seem to crowded. Technically, the script would work with out this extra space. But try it, and I assure you will develop a case of claustrophobia.
mysql_result function, that will be used later, reads rows from MySQL tables starting at row 0, not row 1. Subtracting one from $numoptions is done so that the loop doesn't overshoot its target number, and try to draw an extra bar that doesn't exist. This might be a bit confusing, but the next two line will make things a bit clearer:
$voteoption = mysql_result($optionsquery,$i,'name');
$votevalue = mysql_result($optionsquery,$i,'value');
$voteoptiontakes on the value of the actual name (the 'name' column of the vote options table), and
$votevaluestores the HTML value (the 'value' column of the same table), of the current vote option. The $optionsquery query was the query used earlier to get the total number of vote options. Keep in mind that this loop deals with one vote option at a time, the option that is on row $i. Since $i is incremented after each loop, all vote options are dealt with. We already know how many people have voted overall (
$numvotes), we need to know how many people have voted for the current option specifically.