loomy loomy - 1 year ago 43
MySQL Question

javascript multidimensional array out of mysql table - dont know whats that kind of Object Object

I am trying to get my data out of a mysql table and work with those data in Javascript.
I'm home in php and there are many differences to javascript :( and theres my problem I do think in php and need to understand javascript :)

ok heres the question:
I get from my php script the data out of the table in thsi format: used

while($Search=mysql_fetch_assoc($abfrage)){
$data[] = $Search;
}

echo json_encode( $data );


and get this data:

Array ( [0] => Array ( [id] => 1 [date] => 2017-12-01 [time] => 00:00:00 [active] => 1 ) [1] => Array ( [id] => 2 [date] => 2017-12-02 [time] => 00:00:00 [active] => 1 ) [2] => Array ( [id] => 3 [date] => 2017-12-08 [time] => 00:00:00 [active] => 1 ) [3] => Array ( [id] => 4 [date] => 2017-12-09 [time] => 00:00:00 [active] => 1 ) [4] => Array ( [id] => 5 [date] => 2017-12-15 [time] => 00:00:00 [active] => 1 ) [5] => Array ( [id] => 6 [date] => 2017-12-16 [time] => 00:00:00 [active] => 1 ) [6] => Array ( [id] => 7 [date] => 2017-12-22 [time] => 20:00:00 [active] => 1 ) )


so I used then javascript to get an array or object or whatever this is. I dont really know much about objects-.

var myArr = JSON.parse


to get an array out of this data:

[[object Object] {
active: "1",
date: "2017-12-01",
id: "1",
time: "00:00:00"
}]


what does this
[[object Object]
mean is this an array or an object and how do I work with it?

My goal is to see if there is a date inside the data which comes from the database and if yes check if there is also a time set to this date.

I've made an example at jsbin for testing but I dont know how to go on to receive the data I want:
http://jsbin.com/wariparoce/edit?html,js,console,output

Thanks for all your time and patience :)

Stev

Answer Source

Try accessing to

 myArr.[0].active;
 myArr.[0].date;
 .....

this should return the element in idenx 0 of the field active, date ,,

this mean that you obtain an array ( 0 index based) of object with struct like you PHP assocative array .. where the key in PHP is the key name in JSOn )

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download