Jump to content
MakeWebGames

Storing table values in a JS array?


Script47

Recommended Posts

Updated OP to make it more clear.

"PHP table values"... are you referring to a database table?

I'm still confused what you're asking. It seems more like you're wanting to load a PHP array into Javascript.

If so you'll probably want to look into JSON:

http://www.caveofprogramming.com/frontpage/articles/php/php-json-an-example-javascript-json-client-with-php-server/

Link to comment
Share on other sites

"PHP table values"... are you referring to a database table?

I'm still confused what you're asking. It seems more like you're wanting to load a PHP array into Javascript.

If so you'll probably want to look into JSON:

http://www.caveofprogramming.com/frontpage/articles/php/php-json-an-example-javascript-json-client-with-php-server/

Sorry pal, I thought I made it clear. :)

 

file.php
$query = $db->prepare("some query"); 
$query->execute();
echo json_encode($query->fetchAll(PDO::FETCH_ASSOC));

 

someJsFile.js

$.post('file.php', function (data) {
   var jsArray = $.parseJSON(data); // Any data returned in file.php in a JS array
});

 

Links:

http://en.wikipedia.org/wiki/JSON

http://www.json.org/

Thanks Dayo, this is what I mean't. :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...