开发者

idea to add javascript array to database using PHP

开发者 https://www.devze.com 2023-01-12 00:19 出处:网络
i need to push data in javascript array into database using PHP first i have multidimentional array in js.

i need to push data in javascript array into database using PHP

first i have multidimentional array in js.

Brady [0] [0] = "1";
Brady [0] [1] = "Carol";
Brady [1] [0] = "2";
Brady [1] [1] = "Jan";
Brady [2] [0] = "3";
Brady [2] [1] = "Mike";

and i have table in database such as (id, name)

second if i need to delete some rows in array before i added how can i do?

third how can i push it to database after i d开发者_运维百科elete data in array?


Pass it to PHP as a JSON-encoded string, let PHP reconstruct it as a PHP array using json_decode(), and then just treat it like a normal PHP array.


You must know the basics of AJAX concept. Parameter passing of its your own interest either

  1. separate items

    ex: xmlHttpReq.open('GET', "/test.json&day=" + day + "&month=" + month + "&year=" + year, true);

  2. concat array as a string with special character and send ,parse it at backend

    ex:

    string sample=array[0]+'|'+array1....

       xmlHttpReq.open('GET', "/test.json&arrtest=" +sample , true);
    

    at backend use explode string to make it as array again.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号