Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript数组到php数据库,并将其作为javascript数组返回_Javascript_Php_Mysql_Arrays_Database - Fatal编程技术网

javascript数组到php数据库,并将其作为javascript数组返回

javascript数组到php数据库,并将其作为javascript数组返回,javascript,php,mysql,arrays,database,Javascript,Php,Mysql,Arrays,Database,嗨,我有javascript数组,我想把它转换成mysql数据库,然后我想把它作为javascript数组拿回来 var bookmark = new Array(); bookmark[0] = new Array(); bookmark[1] = new Array(); bookmark[2] = new Array(); // set your bookmarks here: (If you do not fill 'thumb' for thumbnail will be used

嗨,我有javascript数组,我想把它转换成mysql数据库,然后我想把它作为javascript数组拿回来

var bookmark = new Array();
bookmark[0] = new Array();
bookmark[1] = new Array();
bookmark[2] = new Array();

// set your bookmarks here: (If you do not fill 'thumb' for thumbnail will be used title)
// 1. BLOCK
bookmark[0][0] = {
    'title': 'gmail',
    'url': 'http://gmail.com',
    'thumb': 'gmail.png'
};
bookmark[0][1] = {
    'title': 'wikipedia',
    'url': 'http://wikipedia.org',
    'thumb': 'wikipedia.png'
};
bookmark[0][2] = {
    'title': 'YahooMail',
    'url': 'http://mail.yahoo.com',
    'thumb': 'yahoomail.png'
};
bookmark[0][3] = {
    'title': 'hotmail',
    'url': 'http://www.outlook.com/',
    'thumb': 'outlook.png'
};
bookmark[0][4] = {
    'title': 'youtube',
    'url': 'http://youtube.com',
    'thumb': 'youtube.png'
};
bookmark[0][5] = {
    'title': 'google',
    'url': 'http://google.com',
    'thumb': 'google.png'
};
bookmark[0][6] = {
    'title': 'twitter',
    'url': 'http://twitter.com/',
    'thumb': 'twitter.png'
};
bookmark[0][7] = {
    'title': 'MySpace',
    'url': 'http://www.myspace.com/',
    'thumb': 'myspace.png'
};
bookmark[0][8] = {
    'title': 'msn',
    'url': 'http://www.msn.com/',
    'thumb': 'msn.png'
};
bookmark[0][9] = {
    'title': 'facebook',
    'url': 'http://facebook.com',
    'thumb': 'facebook.png'
};
bookmark[0][10] = {
    'title': 'Yahoo',
    'url': 'http://yahoo.com/',
    'thumb': 'yahoo.png'
};
bookmark[0][11] = {
    'title': 'bing',
    'url': 'http://www.bing.com/',
    'thumb': 'bing.png'
};
// end of 1. BLOCK
// 2. BLOCK
bookmark[1][0] = {
    'title': 'linkedin',
    'url': 'http://www.linkedin.com/',
    'thumb': 'linkedin.png'
};
bookmark[1][1] = {
    'title': 'digg',
    'url': 'http://digg.com/',
    'thumb': 'digg.png'
};
bookmark[1][2] = {
    'title': 'flickr',
    'url': 'http://www.flickr.com/',
    'thumb': 'flickr.png'
};
bookmark[1][3] = {
    'title': 'pinterest',
    'url': 'http://pinterest.com',
    'thumb': 'pinterest.png'
};
bookmark[1][4] = {
    'title': 'reddit',
    'url': 'http://www.reddit.com/',
    'thumb': 'reddit.png'
};
bookmark[1][5] = {
    'title': 'technorati',
    'url': 'http://technorati.com/',
    'thumb': 'technorati.png'
};
bookmark[1][6] = {
    'title': 'eurosport',
    'url': 'http://espn.com',
    'thumb': 'espn.png'
};
bookmark[1][7] = {
    'title': 'delicious',
    'url': 'http://www.delicious.com/',
    'thumb': 'delicious.png'
};
bookmark[1][8] = {
    'title': 'ebay',
    'url': 'http://www.ebay.com/',
    'thumb': 'ebay.png'
};
bookmark[1][9] = {
    'title': 'amazon',
    'url': 'http://www.amazon.com/',
    'thumb': 'amazon.png'
};
bookmark[1][10] = {
    'title': 'tumblr',
    'url': 'http://www.tumblr.com/',
    'thumb': 'tumblr.png'
};
bookmark[1][11] = {
    'title': 'StumbleUpon',
    'url': 'http://www.stumbleupon.com/',
    'thumb': 'stumbleupon.png'
};
// end of 2. BLOCK
// 3. BLOCK
bookmark[2][0] = {
    'title': 'filenurse',
    'url': 'http://findgram.com/',
    'thumb': 'findgram.png'
};
bookmark[2][1] = {
    'title': 'upperpix',
    'url': 'http://upperpix.com/',
    'thumb': 'upperpix.png'
};
bookmark[2][2] = {
    'title': 'Videolikers',
    'url': 'http://clipstagram.com',
    'thumb': 'clip.png'
};
bookmark[2][3] = {
    'title': 'InfoVirus',
    'url': 'http://infovirus.org',
    'thumb': 'infovirus.png'
};
bookmark[2][4] = {
    'title': 'websyrup',
    'url': 'http://websyrup.net',
    'thumb': 'websyrup.png'
};
bookmark[2][5] = {
    'title': 'ArcadeOK',
    'url': 'http://arcadeok.com/',
    'thumb': 'arcadeok.png'
};
bookmark[2][6] = {
    'title': 'tvnations',
    'url': 'http://tvnations.com/',
    'thumb': 'tvnations.png'
};
bookmark[2][7] = {
    'title': 'Pixeditor',
    'url': 'http://pixeditor.net/',
    'thumb': 'pixeditor.png'
};
bookmark[2][8] = {
    'title': 'worldchat',
    'url': 'http://worldchat.tv/',
    'thumb': 'worldchat.png'
};
bookmark[2][9] = {
    'title': 'Discoverbit',
    'url': 'http://discoverbit.com/',
    'thumb': 'discoverbit.png'
};
bookmark[2][10] = {
    'title': 'virtualpiano',
    'url': 'http://virtualpiano.eu/',
    'thumb': 'virtualpiano.png'
};
bookmark[2][11] = {
    'title': 'MovieLikers',
    'url': 'http://movielikers.com',
    'thumb': 'movielikers.png'
};
我使用这个脚本从上面的数组中获取数据

var j=0;
for (j=0; j <= (num-1); j++) {      
    for(i=0;i<=11;i++){                             
        var title = bookmark[j][i]['title'];
        var url = bookmark[j][i]['url'];
        var thumb = bookmark[j][i]['thumb'];
        if(thumb==''){
            $('#thumb'+(j+1)+'-'+(i+1)).html('<img id="net" src="lib/net-back.png" /><a href="'+url+'"><div class="title">'+title+'</div></a>');
        }
        else{
            $('#thumb'+(j+1)+'-'+(i+1)).html('<a href="'+url+'"><img src="thumbs/'+thumb+'" /></a>');
        }
    };
};
var j=0;

对于(j=0;j请使用JSON.example和“bookmark”变量

javascript

var bookmarkJSON = JSON.stringify(bookmark); // => this is a string, save this to database
php


我认为使用JSON对象会更容易,然后使用JSON_encode、JSON_decode+1转换到PHP和返回会更容易,使用JSON会让你的生活更轻松。我不确定你在最后一行中“丢失我的javascript”是什么意思?
<?php 
   $bookmark;
   // get $bookmark value from database where you've saved it before
?>
<script>
   var bookmark = <?php echo $bookmark ?>; // => now you can use the "bookmark" variable in javascript
</script>