I'm trying to retrieve some data from my database with php, store it in a javascript array and then change some DOM element with it. I've managed to retrieve data but now I cannot seem to figure out how to store that data in a javascript array. Here's the code I'm using:
My php variable var_dump($result)
gives me:
array(1) { [0]=> array(12) { ["id"]=> string(1) "9" ["name"]=> string(7) "Renessa" ["employee_full_name"]=> string(16) "Renessa Tabassum" ["username"]=> string(11) "emp-renessa" ["password"]=> string(6) "123456" ["email"]=> string(17) "renessa@gmail.com" ["phone"]=> string(11) "01911566321" ["salary"]=> string(5) "15000" ["type"]=> string(6) "Driver" ["gender"]=> string(6) "Female" ["join_date"]=> string(10) "2017-12-16" ["rating"]=> string(1) "0" } }
Now I want to store it in a javascript array, so I did the following:
<script type="text/javascript">
var searchQuery = new Array();
<?php foreach($result as $value){ ?>
searchQuery.push('<?=$value;?>');
<?php } ?>
alert(searchQuery);
</script>
But nothing happens. I checked my browser's console tab, but it says
Uncaught SyntaxError: Invalid or unexpected token
on line 34, but that line literally contains nothing.
How do I do this? Thanks in advance! :)