I"m trying khổng lồ create a json object from MySQL results, but not getting the result I need.

Here is the PHP

$json = array();$result = mysqli_query ($connection, $query); echo "."","; echo ""longitude":"".$row."","; echo ""icon":".""./images/".$row.".png""; echo "}"; } echo ">"; $jsonstring = json_encode($json); echo $jsonstring; die(); It outputs this

But I want this

once I get the result I need to pass the object to a jQuery plugin function if that makes any difference

$.getJSON("myJsonURL, function(myMarkers) $("#map").goMap( markers: myMarkers ););Thanks

php jquery mysql json google-maps-api-3 nói qua Follow edited Jun 17 "11 at 16:55

Programmer Bruce 57.5k66 gold badges9595 silver badges9393 bronze badges asked Dec 22 "10 at 8:22

JCamJCam 56633 gold badges88 silver badges1515 bronze badges 1 địa chỉ cửa hàng a bình luận |

3 Answers 3

Active Oldest Votes26I guess the correct way to bởi vì this would be:

$json = array();$result = mysqli_query ($connection, $query);while($row = mysqli_fetch_array ($result)) $bus = array( "latitude" => $row, "longitude" => $row, "icon" => "./images/" . $row . ".png" ); array_push($json, $bus);$jsonstring = json_encode($json);echo $jsonstring;die(); tóm tắt Follow answered Dec 22 "10 at 8:35


RabidFireRabidFire 6,12011 gold badge2525 silver badges2424 bronze badges 2 địa chỉ cửa hàng a bình luận | 7you output your json by hand and then you điện thoại tư vấn json_encode on an empty array() - $json

json_encode() outputs on you pass an empty array so your last comes from here$jsonstring = json_encode($json); echo $jsonstring;Edit: More about json_encode json_encode php manual

chia sẻ Follow answered Dec 22 "10 at 8:26

cristiancristian 8,26033 gold badges3535 silver badges4343 bronze badges 3 add a comment | 5You start by defining an array.

Bạn đang xem: Hiểu rõ về json là gì? converting an object to json in php

Bạn đã xem: Php return json php json, converting an object to lớn json in php

You then generate some JSON manually.

You then convert the array lớn JSON và output it.

Xem thêm: vợ chồng hết tình cảm

chia sẻ Follow answered Dec 22 "10 at 8:25

QuentinQuentin 787k9999 gold badges10681068 silver badges11941194 bronze badges 3 địa chỉ cửa hàng a phản hồi |

Your Answer

Thanks for contributing an answer to Stack Overflow!

Please be sure lớn answer the question. Provide details và share your research!

But avoid

Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

Draft savedDraft discarded

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using e-mail and Password Submit

Post as a guest

Name email Required, but never shown

Post as a guest

Name email

Required, but never shown

Post Your Answer Discard

By clicking “Post Your Answer”, you agree to lớn our terms of service, privacy policy & cookie policy

Not the answer you're looking for? Browse other questions tagged php jquery mysql json google-maps-api-3 or ask your own question.

The Overflow Blog Featured on Meta Visit chat Linked0jquery ajax not catch the data back Related 0 How can I pass the values of a jQuery callback function lớn a PHP script for further validation? 1220 How vị I get ASP.NET website API to lớn return JSON instead of XML using Chrome? 0 MySQL order by return of PHP function 4 Assigning identifier/name lớn JSON object in PHP 0 địa chỉ markers to lớn google maps from external api url? 3 Convert Large number of mysql records khổng lồ json using php 1 parsing JSON in php using angularJS object 0 How to update MySQL column with thousands of data in PHP automatically using json data Hot Network Questions more hot questions

Question feed Subscribe to RSS Question feed lớn subscribe khổng lồ this RSS feed, copy & paste this URL into your RSS reader.