calling a php function to access a MySQL database from javascript
i am mixing javascript and php to graph sales dynamically from a mysql database - unfortunately i can only plot 1st sales value - i basically need javascript to call a php function that queries the database and returns the next sales value - here is a snippet from the php file
$x=0;
echo "
function loop() {
ctx.clearRect(0, 0, canvas.width, canvas.height);";
$qt=mysql_query("select sales from gd_graph");
$y = mysql_result($qt, $x);
$x+=1;
echo "
yy_prev=yy;
yy=" . $y .";\n";
echo "
for(var i = 0; i < NUM_PARTICLES; i++) {
particles[i].update();
ctx.moveTo(particles[i].x, yy);
ctx.lineTo(particles[i].x - particles[i].xvel, yy_prev);
ctx.stroke();
ctx.closePath();
}
setTimeout(loop, 1000);
}
any ideas much appreciated
cheers
Abbey
|