I need help with my college project. I am downloading data from the database in the form of an Array, how can I download only the text content and e.g. display it in the console?
PHP file on server
<?php
include('db.php');
$Username = $decodedData['Username'];
$sql=mysqli_query($conn,"SELECT text FROM scanned WHERE username = '$Username'");
/*every time it fetches the row, adds it to array...*/
while($r[]=mysqli_fetch_array($sql));
echo json_encode($r);
?>
A function that sends data to the server and receives the result as Array
function getItem(username){
var InsertAPIURL = "http://192.168.0.87/AM_LOGIN/getScanned.php";
let text;
var headers = {
Accept: "application/json",
"Content-Type": "application/json",
};
var Data = {
Username: username,
};
fetch(InsertAPIURL, {
method: "POST",
headers: headers,
body: JSON.stringify(Data), //convert data to JSON
})
.then((response) => response.json()) //check response type of API (CHECK OUTPUT OF DATA IS IN JSON)
.then((response) => {
text = response
console.log(JSON.stringify(text))
})
.catch((error) => {
alert("[BŁĄD]" + error);
});
}
Result
Thanks for help