Variable error with assigned array

0

I'm making a map that shows information, located in a database, through bookmarks. So far, I can only show the last data in the database. What should I do to resolve this problem?

PS: This is done in PHP and JS.

BODY

echo' <script>
                function myMap() {
                    var myCenter = new google.maps.LatLng('.$users_dumps_map[$dump['container_id']].');
                    var mapCanvas = document.getElementById("map");
                    var mapOptions = {
                        center: myCenter,
                        zoom: 5
                    };
                    var map = new google.maps.Map(mapCanvas, mapOptions);
                    var marker = new google.maps.Marker({
                    foreach( $user_dumps as $dump1){
                        position: "'.$users_dumps_map[$dump['container_id']].'"
                       }
                    });
                    marker.setMap(map);

                    var infowindow = new google.maps.InfoWindow({
                        content: "Peso: <b>'.$dump['quantity'].'</b> kg<br>Data/Hora: <b>'.$dump['timestamp'].'</b>"
                    });
                    infowindow.open(map, marker);
                }
                </script>';

                echo'<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBQLYmqoQA-KRJUs7gQ_ahwiLAiuUdVPd0&callback=myMap"></script>';}

PHPCONFIG

<?php$db_name='db.db';$db_drvr='sqlite';$user_info=Array();$user_dumps=Array();$containers=Array();$users_dumps_map=Array();try{$pdo=newPDO("$db_drvr:$db_name");
            $ui_query = $pdo->prepare('SELECT * FROM users WHERE id = :user_id');
            $ui_query->bindParam(':user_id', $_POST['user_id'], PDO::PARAM_INT);
            $ui_query->execute();
            $user_info = $ui_query->fetch(PDO::FETCH_ASSOC);

            $ud_query = $pdo->prepare('SELECT * FROM garbage WHERE user_id = :user_id');
            $ud_query->bindParam(':user_id', $_POST['user_id'], PDO::PARAM_INT);
            $ud_query->execute();
            $user_dumps = $ud_query->fetchAll(PDO::FETCH_ASSOC);

            $c_query = $pdo->prepare('SELECT * FROM containers');
            $c_query->execute();
            $c_results = $c_query->fetchAll(PDO::FETCH_ASSOC);
            foreach( $c_results as $dump ){
                $containers[$dump['id']] = $dump['location'];
                $users_dumps_map[$dump['id']] = $dump['coord'];
            }


        }
        catch(PDOException $e){
            var_dump($e);
            $user_info = Array();
            $user_dumps = Array();
        } 
    ?>

DB

BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS 'users' (
    'id'    TEXT,
    'nome'  TEXT NOT NULL,
    'telemovel' INTEGER,
    'nif'   INTEGER NOT NULL,
    'email' TEXT,
    'morada'    TEXT
);
INSERT INTO 'users' VALUES ('1','Tiago Miguel da Gama Gonçalves
',1234,45643567,'[email protected]','R. C');
INSERT INTO 'users' VALUES ('2','Alexandre Salgado',66578,26458345,'[email protected]','R. A');
INSERT INTO 'users' VALUES ('3','Ricardo Cardoso',5687,34563856,'[email protected]','r. B');
CREATE TABLE IF NOT EXISTS 'garbage' (
    'user_id'   INTEGER,
    'container_id'  INTEGER,
    'quantity'  REAL,
    'timestamp' NUMERIC,
    PRIMARY KEY('user_id','container_id','quantity','timestamp')
);
INSERT INTO 'garbage' VALUES (1,1,1.23,'2018/08/01 19:22:02');
INSERT INTO 'garbage' VALUES (1,2,56.9,'2018/08/01 19:22:02');
INSERT INTO 'garbage' VALUES (1,3,12.0,'2018/08/01 19:22:02');
INSERT INTO 'garbage' VALUES (1,4,19293.3,'2018/08/01 19:22:02');
INSERT INTO 'garbage' VALUES (2,1,231.2,3457345835435);
INSERT INTO 'garbage' VALUES (2,1,231.2,231);
INSERT INTO 'garbage' VALUES (2,1,231.2,34565684562);
INSERT INTO 'garbage' VALUES (2,1,231.2,3456);
INSERT INTO 'garbage' VALUES (2,1,231.2,13412351);
INSERT INTO 'garbage' VALUES (2,1,231.2,243526);
INSERT INTO 'garbage' VALUES (2,1,231.2,456756784567);
INSERT INTO 'garbage' VALUES (2,1,231.2,2346);
CREATE TABLE IF NOT EXISTS 'containers' (
    'id'    INTEGER PRIMARY KEY AUTOINCREMENT,
    'location'  TEXT,
    'coord' TEXT
);
INSERT INTO 'containers' VALUES (1,'R. Dr. Lino Cardoso','40.349859, -8.583798');
INSERT INTO 'containers' VALUES (2,'Largo do rato','38.720430, -9.154948');
INSERT INTO 'containers' VALUES (3,'R. Dom João de Castro ','41.159531, -8.659574');
INSERT INTO 'containers' VALUES (4,'R. Cancioneiro ','40.3497085,-8.5958659');
COMMIT;
    
asked by anonymous 14.08.2018 / 17:36

0 answers