【问题标题】:Line graphs from MySQL data来自 MySQL 数据的折线图
【发布时间】:2012-07-03 18:55:56
【问题描述】:

这是我的代码,我想在其中使用来自 MySQL 的数据创建折线图。任何帮助都将不胜感激,就好像我给了数组一个 fiext 值它会生成图形但现在使用查询它没有显示任何东西。

<?php
function linegraph ($arrval) 
{
$arrval;
$height = 260;
$width = 330;
$im = imagecreate($width,$height);
$white = imagecolorallocate($im,255,255,255);
$gray = imagecolorallocate($im,200,200,200);
$black = imagecolorallocate($im,0,0,0);
$red = imagecolorallocate($im,255,0,0);
$x = 21;
$y = 11;
$num = 0;
while(($x <= $width) && ($y <= $height))
{
    $prcnt = ((($height-50)-($y-1))/($height-60))*100;
    imageline($im, 21, $y, $width-10, $y, $gray);
    imageline($im, $x, 11, $x, $height-50, $gray);
    imagestring($im,2,1,$y-10,$prcnt.'%',$red);
    imagestring($im,2,$x-3,$height-40,$num,$red);
    $x += 30;
    $y += 20;
    $num++;
}
$tx = 20;
$ty = 210;
foreach($arrval as $values)
{
    $cx = $tx + 30;
    $cy = 200-$values;
    imageline($im,$tx,$ty,$cx,$cy,$red);    
    imagestring($im,5,$cx-3,$cy-13,'.',$red);
    $ty = $cy;
    $tx = $cx;
}
imageline($im, 20, 11, 20, $height-50, $black);
imageline($im, 20, $height-49, $width-10, $height-49, $black);
return imagepng($im);
}
include ('/dbcon.php');
$dataarray = array();
$qr = "SELECT * FROM indicator WHERE indicatorid = '83';";
$res = mysql_query($qr);
if($res)
{
    $Data = mysql_fetch_array($res);
    $topicid = $Data['topicid'];
    $indid = 83;
    $couid = 8;
    $year = 2011-10;
    for ($count=0; $count < 10; $count ++)
    {
        $qrdb = "SELECT value FROM databank WHERE topicid = '$topicid', indicatorid = '$indid', countryid = '$couid', yearid = '$year';";
        $result = mysql_query($result);
        if ($result)
        {
            $DDB = mysql_fetch_array($result);
            $dataarray[$count] = $DDB['value'];
        } else {
            echo "Data cannot be fetched form Databank";
        }
    }
}
else
{
    echo "MYSQL query Fail";
}
linegraph($dataarray);
?>

【问题讨论】:

  • 此问题中的信息不足以准确回答,但您可能需要考虑使用mysql_fetch_assoc 而不是mysql_fetch_array。实际上,您可能不想使用其中任何一个功能,因为它们都已被弃用...

标签: php mysql linegraph


【解决方案1】:

您的查询有误

SELECT value FROM databank 
WHERE topicid = '$topicid', 
indicatorid = '$indid', 
countryid = '$couid', 
yearid = '$year';"

当你制作update时,你应该使用,,当你制作select时,你必须使用logical connectors

像这样尝试:

SELECT value FROM databank 
WHERE topicid = '$topicid' and 
indicatorid = '$indid' and
countryid = '$couid'and 
yearid = '$year';"

【讨论】:

    猜你喜欢
    • 2013-05-07
    • 1970-01-01
    • 2023-03-23
    • 2017-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-23
    • 2015-12-31
    相关资源
    最近更新 更多