my final goal is to convert data from database to a array, then i can print a pretty nice graph with a jquery plugin "flot" in html file:
<script language="javascript" type="text/javascript" src="jquery.flot.js"></script>
<script type="text/javascript" >
$(function test() {
var d3= [[0, 3], [4, 8], [8, 5], [9, 13]];
$.plot($("#placeholder"), [d3]);
});
</script>
in php file
echo"<script language='javascript' >\n";
$k = 0;
$agevi = mysql_result($result, $k, "Age");
$snvi = mysql_result($result, $k, "StuNo");
settype($agevi, "integer");
settype($snvi, "integer");
$smallarray = array($snvi,$agevi);
$bigarray = array($smallarray);
$i++;
while ($i < $number)
{
$agev = mysql_result($result, $i, "Age");
$snv = mysql_result($result, $i, "StuNo");
settype($agev, "integer");
settype($snv, "integer");
$smallarray = array($snv,$agev);
array_replace($smallarray,$smallarray);
array_push($bigarray,$smallarray);
echo"\n";
$i++;
}
echo 'var stunoarr = '.json_encode($bigarray).';';
}
echo"\n</script>";
echo json_encode($bigarray) ;
echo "\ndocument.write(\"bigarray array is: <b>" . json_encode($bigarray) . "</b>\")";
mysql_free_result($result);
mysql_close();
what i have in php output is work:
[[1,12],[2,5],[3,6],[4,2],[5,7],[6,2],[7,12],[8,3],[9,6],[10,8],[11,4]] document.write("bigarray array is: [[1,12],[2,5],[3,6],[4,2],[5,7],[6,2],[7,12],[8,3],[9,6],[10,8],[11,4]]")
so people suggesting use json, yes i did, and i also put
<script>
var myvar = <?= json_encode($bigarray); ?>;
</script>
at the end of php file outside ?>
how exactly should get the variable from php to javascript in order to produce the graph then..? tried hundrd of ways now still not working...thanks in advance! :D
flot
means that you understand whatflot
expects, in addition to understanding how the language you're using to manipulate the output itself works. – Jared Farrish Oct 10 '11 at 3:21