views:

62

answers:

2

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?

+5  A: 

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.

TML
A: 

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.

Paniyar