0

I need to how I can use data that I fetched from the database and put into a JSON Object inside a php-file in another (Javascript)-File, where the data is supposed to end up inside an array.

function loadApplicationList()
{
$email = $_GET['email'];

     $listcontent = queryDB("
     SELECT Application.FavRank, Proposal.Title, Proposal.pdfName, RegisteredUser.Name
     FROM Application
     LEFT JOIN user_application
     ON Application.ID = user_application.ID AND user_application.eMail = '$email'
     LEFT JOIN Proposal
     ON Proposal.ID = Application.Proposal_ID
     LEFT JOIN RegisteredUser
     ON RegisteredUser.eMail = Proposal.AuthorEmail;");

     $encodeContent = json_encode($listcontent);
}

?>

Above is the php code, below the JS code

let data = [
// this array is supposed to contain the data from the JSON Object

];

I should also mention that I am new to these languages, so I might've already 'found' the right answer during my hour long research online but wasn't capable to identify it. Thanks for your help in advance.

  • There are really a few ways to do this, it all depends on your specific implementation. You could echo the json to the HTML file in PHP and have it in a script tag. Or you could always load the PHP file via a ajax/fetch call. Since you have the JSON on page load, adding another call via ajax/fetch is really not needed though and adds additional load time waiting for that content to be loaded – imvain2 Jul 14 '22 at 21:42
  • Your query is insecure and should not be used. – mickmackusa Jul 14 '22 at 23:30

0 Answers0