D
D
Dmitry2015-10-24 19:09:53
JavaScript
Dmitry, 2015-10-24 19:09:53

How to save Array to MySQL database correctly?

Javascript forms an array of the form

[manufacters] => Array
        (
            [51] => Array
                (
                    [7] => Array
                        (
                            [name] => Производитель 1
                            [id] => 7
                            [model] => 51
                            [count] => 1
                            [date] => 2015-10-23 00:00:00
                        )
                )
        )

where as an index, I use the IDs I need.
When saving an array to a database.. I convert it to JSON
[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,[null,null,null,null,null,null,null,{"name":"Производитель 1","id":"7","model":"51","count":"0"}]]

Actually the question .. is it possible to somehow avoid ... null,null,null,null,null
... the range of used IDs will be large.. accordingly, the number of null,null,null,null,null... will also be large...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vitaly Inchin ☢, 2015-10-24
@In4in

Ugliness! Use not an array, but the simplest and most banal object.

{
   22 : {
         one : "something",
         two : "yet something"
   },
   35 : {
         one : "something",
         two : "yet something"
   }
}

D
Deodatuss, 2015-10-24
@Deodatuss

serialize unserialize

D
Dmitry, 2015-10-24
@falcon_sapsan

I tried the object.. the result is the same..
var manufacter = new Object();
manufacter[ID] = VAL ...
JSON.stringify(manufacter)
maybe I'm doing something wrong?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question