displaying data returned from php/mysql in a java me application

blossompark
blossompark used Ask the Experts™
on
Hi,
     i use a php file to return data to a java me mobile  phone application and i want to display this info in some sort of table as i do not like how it currently displays (see attachment) returned datai've seen some information regarding json  and am wondering if this is the way to go.... although it seems like overkill for what i want ...any advice appreciated...
thanks
<?php

// this contains MySQL connection info
include("dbinfo.php");

//this creates a variable containing the
// MySQL username and password for connection
$sql = mysql_connect(localhost, $user, $pass)
   or die('Connection error: ' . mysql_error());

//this opens a session to the database that
// will be written to  
mysql_select_db($db, $sql)
   or die('Database selection failed.');

//this section defines the query to be fired at the database table
$query = "SELECT mobileNum, lat, lng FROM LiveOnSystem";
//execute the query
$result = mysql_query($query, $sql);
while($row = mysql_fetch_array($result))
  {
  echo $row['mobileNum'] . " "  . $row['lat'] ." "  . $row['lng'];
 
echo " [NEXT JOB]  ";

  }



var_dump($result);
mysql_close($sql);
?>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Multitechnician
Top Expert 2014
Commented:
replace :

$result = mysql_query($query, $sql);
while($row = mysql_fetch_array($result))
  {
  echo $row['mobileNum'] . " "  . $row['lat'] ." "  . $row['lng'];
 
echo " [NEXT JOB]  ";

  }

by something like this :
//....
$result = mysql_query($query, $sql);
$json = array();
while($row = mysql_fetch_array($result))
{
  $json[] = array( "mobileNum" => $row['mobileNum'], "lat" => $row['lat'], "lng" => $row['lng'] );
}
echo json_encode($json);
//...

Open in new window

Author

Commented:
hi leakim971,
 thanks for that, that returns the data in a browser window  in a format that looks like i should be able to sort and display in java me...gives me a path to follow :-)
thanks again....
leakim971Multitechnician
Top Expert 2014

Commented:
You're welcome! Thanks for the points! Have a nice week-end!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial