Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to put data from Javascript array to MySQL?

Status
Not open for further replies.

marijonas

Technical User
Apr 20, 2004
29
SE
Hi!
I have a long array in javascript and and would like to move it to MySQL database.

my array looks something like this:
------------------------
var brands= new Array();
brands[0]='all'
brands[23]='all2'
.......
brands[n]='alln'
------------------------

and then every member in this array has its own array.
------------------------
brandModels[1] = new Array('3000:name_1','1399:name_2','1400:name_3','3438:name_4','5913:name_6','6119:name_7','2928:name_8);
------------------------

I need to put the data a table in such format:
INSERT INTO `site_make` VALUES (number of brands array (n), that arrays members first part, second part)

example:
INSERT INTO `site_make` VALUES (1,3000, name_1);
INSERT INTO `site_make` VALUES (1,1399,name_2);

Thanks for any help!!!
 
You would need to use a server-side script (in PHP, Perl, etc.) to assemble those queries and execute them using the MySQL API.

Your queries could be made more efficient by combining them into one query, and more reliable by naming the fields:
[tt]
INSERT site_make (fldname1,fldname2,fldname3)
VALUES
(1,3000,name_1),
(1,1399,name_2)
[/tt]
 
Thanks, but I would probably need some Javascript that would sort the data that way...
 
I can actualy just make a text file and send it as sql to the database... the script that would deliver the data in the right way is probably the most important.. hmmm maybe I am in the wrong forum...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top