I have 3 HTML dropdown menus for translations, books, and chapters. The selected content of the 1st impacts the content shown on the 2nd, and the 2nd impacts the 3rd. I also need the dropdowns to update in real time so I’m using JavaScript to detect when the selections change.
I want to call this query from the page where the data will be displayed.. “SELECT DISTINCT book FROM translationTable”
I can’t nest PHP Code inside of JS, so how would I call my table using JS if I have a separate file for my DB connection? I want to try to stay as vanilla JS as possible. Thank you.
// server.js
const mysql = require('mysql');
// Create a connection to the database
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'myDB'
});
module.exports = connection;
// book.html
<script>
var sql = "SELECT DISTINCT book FROM translationTable";
result = ?;
displayContent(result);
</script>