0
$markers =array();
$getmap = $mysqli->query("SELECT `desc`,`lat`,`long` FROM map");
$i=0;
$markers = $getmap->fetch_all(MYSQLI_ASSOC);
echo $markers[1]["desc"];
echo $markers;

$markers = json_encode($markers);

How is it possible such that these will flow properly and it will be read by the JS?
var position = (markers[i][lat], markers[i][long]);

6
  • What code? And php or javascript? You should also dump the exact contents of your variables. Commented Jun 27, 2016 at 9:53
  • I am able to dump, but the dump will end up in [{datahere},{datahere}] , which is unable to be read by Javascript. My goal is to convert the SQL result in to a Javascript readable format, which is parsing it through a json_encode. But it is unable to be read due to the {} Commented Jun 27, 2016 at 9:54
  • You need to post the exact code you are using. Commented Jun 27, 2016 at 9:55
  • Updated and seems easier to understand. Commented Jun 27, 2016 at 9:58
  • var markers = <?php echo json_encode($markers); ?>;. But I don't think the way you are assigning values to position is going to work. Commented Jun 27, 2016 at 10:01

1 Answer 1

1

Please try this way: Hopefully it will help:

foreach($markers as $i=>$arrMarkes)
{
   $finalArray[$i] =  $arrMarkes; 
}

echo json_encode($finalArray);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.