I have been attempting to retrieve each member by converting a multidimensional JSON stored in longtext format within MySQL to an array in JavaScript, but unfortunately, my attempts have not been successful.
Here is the approach I have taken:
Firstly, I extract the data from MySQL and convert it into JSON format using PHP.
if( isset( $_GET ) ){
$id = $_GET['id'];
$conn = db_connect();
$id = mysql_fix_string( $conn, $id );
$result = $conn->query("select _usage from SVM where id='$id'")or die(mysqli_error( $conn ));
$rows = array();
while( $re = mysqli_fetch_assoc( $result ) ){
$re['_usage'] = n12br( $re['_usage']);
$re['_usage'] = html_entity_decode( $re['_usage']);
$re['_usage'] = stripslashes( $re['_usage'] );
$rows[] = $re;
}
print( json_decode( $rows ));
}
Now moving onto the JavaScript portion:
$(document).on('click', '.view-subtitle', function(e, ele){
const id = (this).attr("data-value");
$.ajax({ url:'connect_data.php',
type:'GET',
data:{id: id},
success: function(html){
const result = JSON.parse(html);
console.log( typeof( result ) );
console.log( result[0] );
console.log( result[0].subtitle );
console.log( typeof( result[0].subtitle ));
},
error: function(e){
alert(e.responseText);
} ,
return false;
});