Saturday, 31 August 2013

store php multidimensional array in localstorage

store php multidimensional array in localstorage

I'm building a site where a user can use the site and input data. However
to save their data, they need to log into my site (using facebook
connect). The data that they input is stored in a php multidimensional
array with the following structure:
$order = array();
$order[] = array('rank'=>'1', 'day'=>'Tues'); // This $order[] has input
inputted several times by the user
// I haven't included all the code because it's big, all that's really
needed is to see the structure of $order
My question is, how do I convert the php multidimensional array into
javascript and then how do I store it onto localStorage using
localStorage.setItem() so that once they've logged in with facebook
connect I can use that data? Is this the best way of going about it or
should I be doing something else?
<?php
require_once 'src/facebook.php';
$order = array();
$order[] = array('rank'=>$column, 'day'=>$day);
$loginUrl = $facebook->getLoginUrl(array('scope'=>'user_about_me,email'));
?>
<html>
<head>
<script type="text/javascript">
function fblogin() {
var fk = "<?php echo $loginUrl; ?>";
// What do I do here to convert $order into javascript?
// What do I do here to store converted $order onto localStorage()
window.location = "<?php echo $loginUrl; ?>";
}
</script>
</head>
<body>
<INPUT type="image" src="img/fb.png" onclick="fblogin()"/>
</body>
</html>

No comments:

Post a Comment