'How can I list all table in my database and be able use the results to preform functions in Electron or NodeJs
I am trying to create an app where I will be able to list all tables in my database and then when the tables are listed. I want to be able to click each table and it should display all columns of the clicked table in electron or node js.
for example, If I have a database called 'students' and this database has about 3 tables namely 'table1' 'table2' and 'table3' and each table has its own 2 columns that have 'id' and 'name'
so say I want to list all these tables and then if I click on table1 it should take me to table1 and Select all my columns to display.
I have this code below and it helps display the tables but I have no clue of how can I make it perform based on which table I clicked.
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="bootstrap.css">
</head>
<body>
<br>
<br>
<div class="container">
<table class="table table-striped " >
<tr>
<th>Grades </th>
</tr>
<tr id="grades">
</tr>
</table>
</div>
<script type="text/javascript">
var mysql = require('mysql');
var con = mysql.createConnection({
host : "localhost",
user : "root",
password : "",
database : "students"
});
con.connect(function(err) {
if (err) throw err;
console.log('connected');
var sql = "SHOW TABLES FROM students "
con.query(sql, function (err, result, fields) {
if (err) throw Eerr ;
var i;
for (i = 0; i < result.length; i++) {
var cls = document.getElementById("grades");
var list ="<div>"+ result[i].Tables_in_students + "</div><br>";
cls.innerHTML += list;
}
});
});
</script>
</body>
</html>```
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
