دوستان از کمک صمیمانه شما ممنون هستم و امشب روی برنامه ها کار می کنم اما مشکل جدید من برای قسمت رای گیری سایتم است که همه چیزش درست کار می کند اما نتیجه رای گیری به صورت تصویری که باز نمی شه نشان داده می شود. شما تا به حال به این مشکل برخوردید؟
کدهای من
[php]<?php
$vote=$_POST['choice'];
$db = mysql_connect('127.0.0.1','root');
if(!$db)
{
echo " Error : cannot open connection.";
exit;
}
mysql_select_db('user');
if (!empty($vote))
{
$vote = addslashes($vote);
$query = "update ray
set num = num + 1
where raya = '$vote'";
if(!($result = @mysql_query($query, $db)))
{
echo 'Could not connect to db<br />';
exit;
}
}
$query = 'select * from ray';
if(!($result = @mysql_query($query, $db)))
{
echo 'Could not <br />';
exit;
}
$num_candidates = mysql_num_rows($result);
$total_votes=0;
while ($row = mysql_fetch_object ($result))
{
$total_votes += $row->num;
}
mysql_data_seek($result, 0); // reset result pointer
$width=500; // width of image in pixels - this will fit in 640x480
$left_margin = 50; // space to leave on left of image
$right_margin= 50; // ditto right
$bar_height = 40;
$bar_spacing = $bar_height/2;
$font = 'C:\WINDOWS\Fonts\Arial.ttf';
$title_size= 16; // point
$main_size= 12; // point
$small_size= 12; // point
$text_indent = 10; // position for text labels on left
$x = $left_margin + 60; // place to draw baseline of the graph
$y = 50; // ditto
$bar_unit = ($width-($x+$right_margin)) / 100; // one "point" on the graph
$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;
$percent_color = $black;
$bg_color = $white;
$line_color = $black;
$bar_color = $blue;
$number_color = $pink;
ImageFilledRectangle($im,0,0,$width,$height,$bg_co lor);
ImageRectangle($im,0,0,$width-1,$height-1,$line_color);
$title = 'نظر سنجی';
$title_dimensions = ImageTTFBBox($title_size, 0, $font, $title);
$title_length = $title_dimensions[2] - $title_dimensions[0];
$title_height = abs($title_dimensions[7] - $title_dimensions[1]);
$title_above_line = abs($title_dimensions[7]);
$title_x = ($width-$title_length)/2; // center it in x
$title_y = ($y - $title_height)/2 + $title_above_line; // center in y gap
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 /$total_votes)*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/$total_votes)*100));
else
$right_value = 0;
$bar_length = $x + ($right_value * $bar_unit);
ImageFilledRectangle($im, $x, $y-2, $bar_length, $y+$bar_height, $bar_color);
ImageString($im, $main_size, $text_indent, $y+($bar_height/2), "$row->raya", $text_color);
ImageRectangle($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_height/2), $row->num.'/'.$total_votes, $number_color);
$y=$y+($bar_height+$bar_spacing);
}
Header('Content-type: image/png');
ImagePng($im);
ImageDestroy($im);
?> [/php]