I am developing an Android app and I am new to all of this. My data is stored in MySQL on a web server and I am using a PHP script to read data from MySQL and convert to JSON string which then accessed by Android JSON object in my mobile app. All was working fine until I had multiple paragraphs in my MySQL database. When I read MySQL data using PHP and convert that to JSON string, all the paragraphs become one large paragraph. Android app is reading data correctly, but the problem is I still need to read multiple paragraphs as stored in MySQL database. Could anyone guide me to the right direction or sort this out? Help would be appreciated.
Below is the script files in PHP I am using to read MySQL data and convert that to JSON string.
Connection File:
<?php
$db_name = "myDbName";
$mysql_username = "db_user";
$mysql_password = "db_password";
$server_name = "serverName";
$conn = mysqli_connect($server_name, $mysql_username, $mysql_password, $db_name);
$sSQL= 'SET CHARACTER SET utf8';
mysqli_query($conn, $sSQL) or die ('Can\'t charset in DataBase');
if(!$conn)
{
die("Connection failed:" . mysqli_error($conn));
}
?>
Json coversion file:
<?php
require "conn.php";
$sql_qry = "SELECT * FROM tabITArticles;";
$result = mysqli_query($conn, $sql_qry);
$response = array();
while($row = mysqli_fetch_array($result)){
array_push($response, array("id"=>$row[0],"title"=>$row[1],"author"=>$row[2],"content"=>$row[3],"image"=>$row[4],"date"=>$row[5]));
}
echo json_encode(array("server_response"=>$response));
mysqli_close($conn);
?>