• Advertisement
Sign in to follow this  

[web] Sending php varibles to a JS function in an onload call

This topic is 4153 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

<?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).

Share this post


Link to post
Share on other sites
Advertisement
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)?

Share this post


Link to post
Share on other sites
Not really; I was using this library:
http://webfx.eae.net/dhtml/chart/api.html

Share this post


Link to post
Share on other sites
If you want this to be generated dynamically, but once every page refresh only, then just use:

<?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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement