Page 1 of 1

Loading JavaScript Arrays with MySQL Data

Posted: Thu Jul 20, 2006 10:15 am
by Etherguy
Long time no post :)

Was wondering if anyone had any idea on how to Load JavaScript Arrays with MySQL Data. Trying to create a selection system that can utilize both mysql and file calls.

Any help would be greatly appreciated!

Posted: Thu Jul 20, 2006 10:18 am
by Burrito
since js arrays are client side....all you need to do is pass the info down to the client once it's been served by the server:

ex:

Code: Select all

$script = "<script>";
$script .= "var someArr = new Array(";
while($row = mysql_fetch_assoc($result))
  $script .= "'".$row['someJSArrayVal']."'";
$script .= ");";
$script .= "</script>";

echo $script;