Tratando dados Retornados do MySQL+PHP com JQuery

functions.js 

$("#aparelho").change(function(){
    var id = $(this).attr('id');
    $.get("functions.php?func=getLatLong&car=" + $(this).val(), function(dadosRetornados){
      $.each($.parseJSON(dadosRetornados), function (key, value) {
        $("#" + id).after(value.latitude,value.longitude);
      });
    });
  });

functions.php

function getLatLong($car){

  $link = mysql_connect('localhost', 'root', 'passwd') or die(mysql_error());
  mysql_select_db('db') or die(mysql_error());

  $query = "SELECT latitude, longitude
                FROM table
                LIMIT 1";

  $result = mysql_query($query) or die(mysql_error());

  while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

    $arr["{$row['dados']}"]['latitude'] = $row['latitude'];
    $arr["{$row['dados']}"]['longitude'] = $row['longitude'];
  }
  mysql_close($link);

  echo json_encode($arr);
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s