意想不到的'}使用 SQL 和 PHP 绘制图表时
我正在使用 PHP 从 SQL 编写图表。我已经得到了这段代码,但它似乎没有执行。我认为代码是正确的,但显然不是。
代码是:
<?php
header ("Content-type: image/png");
$im = imagecreatefrompng ("graphtemp.png");
$red = imagecolorallocate ($im, 255, 0, 0);
$black = imagecolorallocate ($im, 0, 0, 0);
mysql_connect("localhost", "user", "password");
mysql_query("USE database");
$optionsquery = mysql_query("SELECT * FROM brands");
$numoptions = mysql_num_rows($optionsquery);
$pollquery = mysql_query("SELECT * FROM categories");
$numvotes = mysql_num_rows($pollquery);
$xval = 30;
$barwidth = floor(300/$numoptions);
for ($i=0;$i<=($numoptions-1);$i++)
{
$voteoption = mysql_result($optionsquery,$i,'name');
$votevalue = mysql_result($optionsquery,$i,'value');
$currentnumquery = mysql_query("SELECT * FROM categories WHERE vote='$votevalue'");
$currentnum = mysql_num_rows($currentnumquery);
$per = floor(($currentnum/$numvotes)*184);
$rper = floor(($currentnum/$numvotes)*100);
imagefilledrectangle ($im, $xval, (200-$per), ($xval+$barwidth), 200, $red);
imagerectangle ($im, $xval, (200-$per), ($xval+$barwidth), 200, $black);
imagestring ($im, 1, ($xval+($barwidth/2)), 205, $voteoption, $black);
imagestring ($im, 2, ($xval+($barwidth/2)), ((200-$per)-15), "$rper%", $bla);
$xval+=($barwidth+10)
}
imagepng($im);
?>
当我使用这个时,我收到错误:
Parse error: syntax error, unexpected '}' in /home/user/public_html/graph.php on line 27
谢谢大家!这段代码在这里似乎不起作用,这是错误日志。我正在学习 PHP 和 SQL,所以非常感谢您的帮助。 - http://pastebin.com/Zw18Afne
I'm coding a graph from SQL using PHP. I've got this code and it doesn't seem to execute. I thought the code was right but apprently it's not.
the code is:
<?php
header ("Content-type: image/png");
$im = imagecreatefrompng ("graphtemp.png");
$red = imagecolorallocate ($im, 255, 0, 0);
$black = imagecolorallocate ($im, 0, 0, 0);
mysql_connect("localhost", "user", "password");
mysql_query("USE database");
$optionsquery = mysql_query("SELECT * FROM brands");
$numoptions = mysql_num_rows($optionsquery);
$pollquery = mysql_query("SELECT * FROM categories");
$numvotes = mysql_num_rows($pollquery);
$xval = 30;
$barwidth = floor(300/$numoptions);
for ($i=0;$i<=($numoptions-1);$i++)
{
$voteoption = mysql_result($optionsquery,$i,'name');
$votevalue = mysql_result($optionsquery,$i,'value');
$currentnumquery = mysql_query("SELECT * FROM categories WHERE vote='$votevalue'");
$currentnum = mysql_num_rows($currentnumquery);
$per = floor(($currentnum/$numvotes)*184);
$rper = floor(($currentnum/$numvotes)*100);
imagefilledrectangle ($im, $xval, (200-$per), ($xval+$barwidth), 200, $red);
imagerectangle ($im, $xval, (200-$per), ($xval+$barwidth), 200, $black);
imagestring ($im, 1, ($xval+($barwidth/2)), 205, $voteoption, $black);
imagestring ($im, 2, ($xval+($barwidth/2)), ((200-$per)-15), "$rper%", $bla);
$xval+=($barwidth+10)
}
imagepng($im);
?>
When I use this I get the error:
Parse error: syntax error, unexpected '}' in /home/user/public_html/graph.php on line 27
Thanks guys! This code doesn't seem to work here is the error log. I'm learning PHP and SQL as well so any help is appreciated. - http://pastebin.com/Zw18Afne
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,让我们看一下错误:
好的,该错误基本上是说,PHP 发现了一个它没有预料到的
}
,原因是 php 会跳过代码中的空格、换行符和任何不可见的字符,然后解释代码。所以 PHP 看到你这样的代码
但是正如你所看到的,我在 php 到达的地方放置了一个箭头并说,什么..这里不应该有
}
:/在 PHP 中每行命令都应该用
;
结束,以便 PHP 知道该段代码的结尾,并且第二个代码不是第一个代码的一部分。将冒号放在这里告诉 php 继续执行下一个命令。
ok so let's take a look at the error then:
Ok the error is basically saying, that PHP Found a
}
of witch it didn't expect, the reason for this is that php skips spaces, new lines and any invisible character from the code and then interprets the code.So PHP Sees you code like this
But as you can see, i have placed an arrow where php reaches and says, what.. there should not be a
}
here :/Within PHP Each line of command should be closed with a
;
so that PHP knows that the end of that bit of code, and the second is not part of the first.placing the colon here tells php to move on to the next command.
你后面少了一个分号
You're missing a semicolon after