I am trying to draw on a html canvas using values from a php table. From my testing the php is reading values from the table correctly and is also calling the javascript function, but its not working to draw a series of 20*20 rectangles with a different x value.
<html>
<script type="text/javascript">
function draw( i ) {
alert(i);
var canvas = document.getElementById('mycanvas');
var drawshape = canvas.getContext('2d');
canvas.width = 800;
canvas.height = 400;
drawshape.fillStyle = '#00ff00';
drawshape.fillRect(50 * i , 50, 20, 20);
}
</script>
<body>
<canvas id="mycanvas"></canvas>
</body>
</html>
<?php
$query4 = 'SELECT * FROM graph_table';
$result4 = mysql_query($query4);
while($person4 = mysql_fetch_array($result4)) {
$indent = $person4['indent'];
echo '<script type="text/javascript"> draw( <?php echo $indent; ?> ); </script>';
}
?>
change your draw function
and add a parameter everytime the result from db is generated
ex