<?php
mySQLConnect stuff...
$vals = mysql_num_rows($result1);
?>
<body onload="demo('a', 'b', 'c');">..
</body>
I have a JS class that draws a graph and gets called by the demo() function. However, what I'm graphing is data I pull out of a mySQL db. So I get the data with php, but I don't know how to send it to the JS call so that I can graph it. Ex: so instead of demo(a, b, c), I need demo(a, b, $vals).
[web] Sending php varibles to a JS function in an onload call
Using javascript for this seems like unnecessary work. Will it do anything that a static graph generated by PHP wouldn't do (either in HTML or as an image)?
If you want this to be generated dynamically, but once every page refresh only, then just use:
If you have a PHP array with you that you want to give to a function as args, simple use explode() with a comma separator.
On the other hand, if your graph or whatever it is, is going to change dynamically and on-the-fly (multiple times every page refresh) then you may want to look into some basic AJAX techniques like XMLHttpRequest() to talk to the server while a page is being viewed idly.
<?php/* mySQLConnect stuff... */$vals = mysql_num_rows($result1);?><html><body onload="demo('a','b','<?php echo $vals; ?>');"></body>
If you have a PHP array with you that you want to give to a function as args, simple use explode() with a comma separator.
On the other hand, if your graph or whatever it is, is going to change dynamically and on-the-fly (multiple times every page refresh) then you may want to look into some basic AJAX techniques like XMLHttpRequest() to talk to the server while a page is being viewed idly.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement