Forum Moderators: coopster
(excerpt from phplot manual)$example_data = array(
array('a',3),
array('b',5),
array('c',7),
array('d',8),
array('e',2),
array('f',6),
array('g',7)
);
but my data is dynamic and it comes from MySQL table and I need to put it inside an array.
$vtarget=$_GET['s'];$gquery="select ddate,score from data1 where target='$vtarget'";
$gresult=mysql_query($gquery);
$dbres = mysql_fetch_assoc($gresult);
$graph_data = array(
foreach($dbres as $result)
{
array('$result['ddate']',$score),
}
);
$graph_data=$array;
$plot->SetDataValues($graph_data);
this is my code and it is not working no matter how I modify it (im a newbie to php). How do I insert the value of 'ddate' and 'score' inside the array so I can pass it to phplot and create a chart?
I also noticed that if I put it inside the foreach loop, it will give an error because the last element should not have a comma in the end (,).
Thanks in advance.
while ($row = mysql_fetch_row($gresult))
{
$graph_data[]=$row;
}
now my problem is how to make a multi-dimensional array with 3 - 10 elements in each row.
thanks again.
//...
$gquery="select ddate,score from data1 where target='$vtarget'";
$gresult=mysql_query($gquery);
$dbres = mysql_fetch_assoc($gresult); //only one row$graph_data = array( //you can't run loops in declarations
foreach($dbres as $result)
{
array('$result['ddate']',$score));//You write to array text $result... not the variable. But as you don't assign the array it is not used anywhere
}
);
$graph_data=$array; //variable $array is empty - this is the first time it appears$plot->SetDataValues($graph_data);
//...
$gquery="SELECT `ddate`, `score` FROM `data1` WHERE `target`='$vtarget'";
$gresult=mysql_query($gquery);$graph_data = array();
while($dbres = mysql_fetch_assoc($gresult)) //take all results
{
$graph_data[] = array($dbres['ddate'],$dbres['score']);//No ' around variable. $var[] creates new element of an array.
}$plot->SetDataValues($graph_data);
Hope this helps and cleares everything
Michal
aaa
1
3
3
4
2
6
7
bbb
1
2
3
4
3
2
ccc
10
8
9
6
8
9
4
3
so on. it will go up to 10.
my problem is how to put it in a multidimensional array so I can plot it in a chart.
something like this
aaa,1,3,3,4,2,6,7
bbb,1,2,3,4,3,2
ccc,10,8,9,6,8,9,4,3
...
as you will also notice, the numbers is not fixed.
thanks again.
$chart = array();for($j = 1; $j <= 3; $j++)
{
for($i = 1; $i <= 10; $i++)
{
$chart[$j][$i] = get_chart_data($i, $j);
}}
or if you have data in mysql, you can:
$chart = array();
$vars = array("x", "y", "z");
$i = 0;
$j = 0;while($row = mysql_fetch_assoc(...))
{
if($i = 10)
{
$j++;
$i = 0;
}
$chart[$vars[$j]][$i] = $row['value'];
$i++;
}