با سلام :
کد زیر را برای رسم یک سری نمودار ستونی (نتایج فرم نظر سنجی) نوشته ام واطلا عات نظر سنجی را به درستی به پايگاه داده وارد میکنه ولی وقتی میخواهد نمودار رو رسم کنه صفحه سفیدی لود میشه که هیچ تصویری در اون نیست ! کد هم ظاهرا درسته (البته گفتم ظاهرا) هر کی میتونه یه کمکی بکنه ممنون میشم ! (البته php_gdهم فعال است .)
کد زیر را برای رسم یک سری نمودار ستونی (نتایج فرم نظر سنجی) نوشته ام واطلا عات نظر سنجی را به درستی به پايگاه داده وارد میکنه ولی وقتی میخواهد نمودار رو رسم کنه صفحه سفیدی لود میشه که هیچ تصویری در اون نیست ! کد هم ظاهرا درسته (البته گفتم ظاهرا) هر کی میتونه یه کمکی بکنه ممنون میشم ! (البته php_gdهم فعال است .)
<?php
header ("Content-type: image/png");
$vote=$_POST['vote'];
if(! $db_conn=@mysql_connect("dbhost","dbuser","dbpass"))
{
echo'Error ! Cannot Connect to DB !!';
exit;}
@mysql_select_db('poll');
if (!empty($vote))
{
$vote = addslashes($vote);
$query="update poll_resuls
set num_votes = num_votes+1
where candidate = '$vote'";
if (!($result=@mysql_query($query, $db_conn)))
echo 'Error !! Could Not execute The Query !';
exit;
}
else
{
echo'Go Back and Compelete The form';
}
$query ='select * from poll_resuls';
if(!($result = @mysql_query($query, $db_conn)))
{
echo 'Error !! Can not connect to db !';
}
$num_candidates = mysql_num_rows($result);
$total_votes = 0;
while ($row = mysql_fetch_object ($result))
{
$total_votes +=$row-> num_votes;
}
mysql_data_seek($result, 0);
//***********************graphic***************************
$width=500;
$left_margin=50;
$right_margin=50;
$bar_height=40;
$bar_spacing=$bar_height/2;
$font='d:\windows\fonts\arial.ttf';
$title_size=16;
$main_size=12;
$small_size=12;
$text_indent=10;
$x=$left_margin + 60;
$y=50;
$bar_unit=($width-($x+$right_margin))/100;
$height=num_candidates * ($bar_height + $bar_spacing) +50;
$im = imagecreate($width, $height);
$white=ImageColorAllocate($im,255,255,255);
$blue=ImageColorAllocate($im,0,64,128);
$black=ImageColorAllocate($im,0,0,0);
$pink=ImageColorAllocate($im,255,78,243);
$text_color=$black;
$bg_color=$white;
$line_color=$black;
$bar_color=$blue;
$number_color=$pink;
ImageFilledRegtangles($im,0,0,$width,$height,$bg,$bg_color);
ImgeRegtangle($im,0,0,$width-1,$height-1,$line_color);
$title='Poll Results :';
$title_diamentions=ImgaeTTFBbox($title_size, 0, $font, $title);
$title_length=$title_diamentions[2] - $title_diamentions[2] ;
$title_height=abs($title_diamention[7] - $title_diamention[1]);
$title_above_line = abs($title_diamention[7]);
$title_x=($width-$title_length)/2;
$title_t=($y-$title_height)/2 + $title_above_line;
ImageString($im, $title_size, $title_x, $title_y, $title, $text_color);
ImageLine($im, $x, $y-5, $x, $height-15, $line_color);
while($row = mysql_fetch_object($result))
{
if($total_votes>0)
$percent = intval(round(($row->num_vots/$total_vots)*100));
else
$percent=0;
ImageString($im, $main_size, $width-30, $y+($bar_height/2), $percent.'%', $percent_color);
if($total_votes>0)
$right_value= intval(round(($row->num_votes/$total_vots)*100));
else
$right_value = 0;
$bar_length= $x+($right_value * $bar_unit);
ImageFilledRegtangle($im, $x, $y-2, $bar_length, $y+$bar_height, $bar_color);
ImageString($im,$main_size,$text_indent,$y+($bar_height/2),"$row->candidate", $text_color);
ImageRegtangle($im,$bar_length+1,$y-2,($x+(100*$bar_unit)), $y+$bar_height, $line_color);
ImageString($im,$small_size, $x+(100*$bar_unit)-50, $y+($bar_heigth/2), $row->num_votes.'/'.total_votes, $number_color);
$y=$y+($bar_height +$bar_spacing);
}
ImagePng($im);
ImageDestroy($im);
?>
header ("Content-type: image/png");
$vote=$_POST['vote'];
if(! $db_conn=@mysql_connect("dbhost","dbuser","dbpass"))
{
echo'Error ! Cannot Connect to DB !!';
exit;}
@mysql_select_db('poll');
if (!empty($vote))
{
$vote = addslashes($vote);
$query="update poll_resuls
set num_votes = num_votes+1
where candidate = '$vote'";
if (!($result=@mysql_query($query, $db_conn)))
echo 'Error !! Could Not execute The Query !';
exit;
}
else
{
echo'Go Back and Compelete The form';
}
$query ='select * from poll_resuls';
if(!($result = @mysql_query($query, $db_conn)))
{
echo 'Error !! Can not connect to db !';
}
$num_candidates = mysql_num_rows($result);
$total_votes = 0;
while ($row = mysql_fetch_object ($result))
{
$total_votes +=$row-> num_votes;
}
mysql_data_seek($result, 0);
//***********************graphic***************************
$width=500;
$left_margin=50;
$right_margin=50;
$bar_height=40;
$bar_spacing=$bar_height/2;
$font='d:\windows\fonts\arial.ttf';
$title_size=16;
$main_size=12;
$small_size=12;
$text_indent=10;
$x=$left_margin + 60;
$y=50;
$bar_unit=($width-($x+$right_margin))/100;
$height=num_candidates * ($bar_height + $bar_spacing) +50;
$im = imagecreate($width, $height);
$white=ImageColorAllocate($im,255,255,255);
$blue=ImageColorAllocate($im,0,64,128);
$black=ImageColorAllocate($im,0,0,0);
$pink=ImageColorAllocate($im,255,78,243);
$text_color=$black;
$bg_color=$white;
$line_color=$black;
$bar_color=$blue;
$number_color=$pink;
ImageFilledRegtangles($im,0,0,$width,$height,$bg,$bg_color);
ImgeRegtangle($im,0,0,$width-1,$height-1,$line_color);
$title='Poll Results :';
$title_diamentions=ImgaeTTFBbox($title_size, 0, $font, $title);
$title_length=$title_diamentions[2] - $title_diamentions[2] ;
$title_height=abs($title_diamention[7] - $title_diamention[1]);
$title_above_line = abs($title_diamention[7]);
$title_x=($width-$title_length)/2;
$title_t=($y-$title_height)/2 + $title_above_line;
ImageString($im, $title_size, $title_x, $title_y, $title, $text_color);
ImageLine($im, $x, $y-5, $x, $height-15, $line_color);
while($row = mysql_fetch_object($result))
{
if($total_votes>0)
$percent = intval(round(($row->num_vots/$total_vots)*100));
else
$percent=0;
ImageString($im, $main_size, $width-30, $y+($bar_height/2), $percent.'%', $percent_color);
if($total_votes>0)
$right_value= intval(round(($row->num_votes/$total_vots)*100));
else
$right_value = 0;
$bar_length= $x+($right_value * $bar_unit);
ImageFilledRegtangle($im, $x, $y-2, $bar_length, $y+$bar_height, $bar_color);
ImageString($im,$main_size,$text_indent,$y+($bar_height/2),"$row->candidate", $text_color);
ImageRegtangle($im,$bar_length+1,$y-2,($x+(100*$bar_unit)), $y+$bar_height, $line_color);
ImageString($im,$small_size, $x+(100*$bar_unit)-50, $y+($bar_heigth/2), $row->num_votes.'/'.total_votes, $number_color);
$y=$y+($bar_height +$bar_spacing);
}
ImagePng($im);
ImageDestroy($im);
?>