0

This is my code in which I want to create a line graphs using the data from MySQL. Any help will be appreciated as if i gave the array a fiext values it generates the graphs but now using the queries it is not showing any thing.

<?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);
?>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Asim Naseer
  • 143
  • 1
  • 3
  • 11
  • There is not nearly enough information in this question to be able to accurately answer but it looks like you might want to consider using `mysql_fetch_assoc` instead of `mysql_fetch_array`. Actually, you probably don't want to use either of those functions since they are both deprecated... – Matt Dodge Jul 03 '12 at 19:37

1 Answers1

0

you have a mistake in your query

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

you should use , when you are making a update, when you are making a select you have to use logical connectors

try it like this:

SELECT value FROM databank 
WHERE topicid = '$topicid' and 
indicatorid = '$indid' and
countryid = '$couid'and 
yearid = '$year';"
jcho360
  • 3,724
  • 1
  • 15
  • 24