Loading JavaScript Arrays with MySQL Data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Etherguy
Forum Commoner
Posts: 70
Joined: Fri Nov 01, 2002 9:09 pm
Location: Long Island, New York

Loading JavaScript Arrays with MySQL Data

Post 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!
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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;
Post Reply