you would write a JOIN query that gets the data that you want in the order that you want it.
you would build, execute, and fetch the result from that query using whatever php database extension you are using (the PDO extension is the best choice.)
you would format an array of data with those keys and values
you would JSON encode the array of data and output it
which of these steps have you successfully completed, where are you having a problem, and what is your query/code that you need help with? what database server are you using? which php database extension are you using? do you have php's error_reporting set to E_ALL and display_errors set to ON, preferably in the php.ini on your system, so that php will help you by reporting and displaying all the errors it detects? do you have error handling for all the database statements that can fail - connection, query, prepare, and execute so that you will know if and why they are failing? using exceptions for database statement errors and in most cases simply letting php catch and handle the exception will result in database statement errors being 'automatically' displayed/logged the same as php errors.