Reputation: 3128
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 delete data in array?
Upvotes: 1
Views: 533
Reputation: 12966
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.
Upvotes: 6
Reputation: 21068
You must know the basics of AJAX concept. Parameter passing of its your own interest either
separate items
ex: xmlHttpReq.open('GET', "/test.json&day=" + day + "&month=" + month + "&year=" + year, true);
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.
Upvotes: 0