0

I have this array value: print_r ($array); which contains 2 data (this is latt and long of my gmap project).

The array is from:

<?php
if(isset($_GET['q'])) {
    $q = $_GET['q'];
    }
$q = isset($_GET['q']) ? $_GET['q'] : '';
$array = array();
$nsUser="SELECT * FROM cliententry WHERE kampusterdekat=:q";
$uQuery = $mydb->prepare ($nsUser);
$uQuery->execute(array(':q' => $q));
while ($result = $uQuery->fetch(PDO::FETCH_ASSOC)) { 
    $id=$result['id'];
    $googlemap=$result['googlemap'];
    //echo $googlemap;
    $array[] = $googlemap;
    print_r ($array);
    }
?>

When I echo, the result will be like this:

Array
(
    [0] => -5.364000343425874, 105.24465411901474
)
Array
(
    [0] => -5.364000343425874, 105.24465411901474
    [1] => -5.362878747789552, 105.24150252342224
)

Point:
What I need is to make the result into this format:
var wwwsitus = [ ['<h4>area</h4>', wwwsitus[0]], ['<h4>area</h4>', wwwsitus[1]], ];

where locations (<h4>area</h4>) are removed. So, it must be, as follows:
var wwwsitus = [ [...,...], [...,....], ];

Note:
Since I've no capable about array in JS, please help me to fix my title based on my issue. Thks in adv.

Joe Kdw
  • 2,245
  • 1
  • 21
  • 38
  • 2
    What's the issue here exactly? `x` and `y` aren't set that's why there's no marker? The response is returning `-5.364000343425874, 105.24465411901474-5.362878747789552, 105.24150252342224` which looks like it has an issue on formatting the 2 data and when passed the marker, leads to the error. – adjuremods Feb 01 '16 at 07:00
  • @adjuremods: I finally found what the issue is. I just updated my question. It's about separate elements (grabbed from database) into array, and I simple don't know how. - Yes, you're right. pls help me with this – Joe Kdw Feb 01 '16 at 07:05
  • try to change how the response object looks like. For example, return 2 separate JSON Objects for every row from the database. With that, you'll have to change your implementation to cater to it being created into a Marker. – adjuremods Feb 01 '16 at 07:14
  • @adjuremods, you mean I make 2 ajax(s) to handle the latt and long?. In this project, I will make 5 location shown in the map and that means I have to create 5 ajax-calling for the latt and long? – Joe Kdw Feb 01 '16 at 07:23
  • 1
    In the example I gave in the comment, `wwwsitus` will now be a JSONArray, you'll loop through the array to make the Markers. – adjuremods Feb 01 '16 at 07:27
  • 2
    Possible duplicate of [Convert php array to Javascript](http://stackoverflow.com/questions/5618925/convert-php-array-to-javascript) – Joe Kdw Feb 01 '16 at 12:12
  • I close this question since I find the answer at: http://stackoverflow.com/questions/5618925/convert-php-array-to-javascript, thanks for discussion – Joe Kdw Feb 01 '16 at 12:13

0 Answers0