I am creating the android application to communicate from android device to my localhost server. I want to pass two arrays from php file to android. But I don't know how to do that. Please help me for that. I will search it a lot for this but I am not satisfy with my query.
Thanks in advance.
here is my php script.
<?php
// PHP variable to store the host address
$db_host = "localhost";
// PHP variable to store the username
$db_uid = "root";
// PHP variable to store the password
$db_pass = "";
// PHP variable to store the Database name
$db_name = "chatting";
// PHP variable to store the result of the PHP function 'mysql_connect()' which establishes the PHP & MySQL connection
$db_con = mysql_connect($db_host,$db_uid,$db_pass) or die('could not connect');
mysql_select_db($db_name);
@$timestamp=$_POST["timestamp"];
@$message=$_POST["message"];
@$from=$_POST["from"];
@$to=$_POST["to"];
$from_id=1;//$_POST["from_id"];
$to_id=2;//$_POST["to_id"];
$sql1="INSERT INTO messages(from_msg,to_msg,message,timestamp) values('$from_id','$to_id','$message','$timestamp')";
$result1=mysql_query($sql1);
$sql = "SELECT * FROM messages";
$result = mysql_query($sql);
while($row=mysql_fetch_assoc($result))
$output[]=$row["message"];
$sql="SELECT username FROM users WHERE id='".$from_id"'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$sql1="SELECT username from users where id='".$to_id"'";
$result1=mysql_query($sql1);
$row1=mysql_fetch_array($result1);
$chat[]=array(
'from_msg'=>$row['username'],
'to_msg'=>row1['username']);
print(json_encode($output,$chat));
mysql_close();
?>
I want to parse this arrays in android.
json_encode()function, merge them and do pass the single array intojson_encode()function.