no mate, this could be the end of me!lol
$username = $_SESSION['username'];
$testID = $HTTP_SERVER_VARS['QUERY_STRING'];
$query1 = "SELECT * FROM Results WHERE Username = '$username' AND TestID = '$testID' ORDER BY ResultsID DESC";
$result1 = mysql_query($query1);
while($row1 = mysql_fetch_array($result1,MYSQL_ASSOC))
{
$values[] = $row1[TestScore];
}
// Get the total number of columns we are going to plot
$columns = count($values);
// Get the height and width of the final image
$width = 300;
$height = 200;
// Set the amount of space between each column
$padding = 5;
// Get the width of 1 column
$column_width = $width / $columns ;
// Generate the image variables
$im = imagecreate($width,$height);
$gray = imagecolorallocate ($im,255,000,000);
$gray_lite = imagecolorallocate ($im,000,000,000);
$gray_dark = imagecolorallocate ($im,000,000,000);
$white = imagecolorallocate ($im,255,218,185);
// Fill in the background of the image
imagefilledrectangle($im,0,0,$width,$height,$white );
$maxv = 0;
// Calculate the maximum value we are going to plot
for($i=0;$i<$columns;$i++)$maxv = max($values[$i],$maxv);
// Now plot each column
for($i=0;$i<$columns;$i++)
{
$column_height = ($height / 100) * (( $values[$i] / $maxv) *100);
$x1 = $i*$column_width;
$y1 = $height-$column_height;
$x2 = (($i+1)*$column_width)-$padding;
$y2 = $height;
imagefilledrectangle($im,$x1,$y1,$x2,$y2,$gray);
// This part is just for 3D effect
imageline($im,$x1,$y1,$x1,$y2,$gray_lite);
imageline($im,$x1,$y2,$x2,$y2,$gray_lite);
imageline($im,$x2,$y1,$x2,$y2,$gray_dark);
}
// Send the PNG header information. Replace for JPEG or GIF or whatever
header ("Content-type: image/png");
imagepng($im);
?>
Theres the whole block of code, the idea is to create a bar graph with the values from the $values array, but i want to set this array from values in my database. do you understand?
I'm trying to plot exam marks, which will change everytime someone takes the online test i have devised, which are stored in a DB.
thanks, so far mate,
Ash
My new web design domain
www.askmultimedia.co.uk