1

I'm new progressive web app development. I successfully connected to mysql using node.js and extracted user table info but I don't know how to display it in html using the table tagthis is the mysql tables

 var mysql = require('mysql');

var con = mysql.createConnection({
    host: "localhost",
    user: "root",
    password: "",
    database: "election"
});
con.connect(function(err) {
  if (err) throw err;
  con.query("SELECT * FROM admin", function (err, result, fields) {
    if (err) throw err;
    console.log(result);
  });
  con.query("SELECT * FROM user", function (err, result, fields) {
    if (err) throw err;
    console.log(result);
  });
});

this is the selectuser.js to connect and extract user table

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript" src="/db/selectuser.js"></script>
</head>
<body>
    <table>
        <thead>
            <tr>
                <th>user_id</th>
                <th>full_name</th>
                <th>username</th>
                <th>password</th>
                <th>role</th>
            </tr>
        </thead>
        <tbody>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
        </tbody>
    </table>
</body>
</html>

that's the html page (test.html) I'm trying to display each individual users information as a row in the table. Any help please??

tareklk
  • 31
  • 4
  • I'm having trouble displaying the extracted rows from users mysql table as a table in html, not at creating the table dynamically – tareklk Nov 01 '20 at 00:21
  • Look the system with creating rows is the same, you need identifier for every element, which you don't have. try it and the when there is a question, come and ask for it with implemented code, but in short it is the same. – nbk Nov 01 '20 at 00:33
  • I understand that, but my problem is when I extract the users info (user id,name,..) they are stored in result following the javascript file I attached. How do I get access on each value, i.e: the value of result[ RowDataPacket { user_id: 3, full_name: '..', username: '..', password: '..', role: '..' }, RowDataPacket { user_id: ., full_name: '..', username: '..', password: '..', role: '..' } ] I want to access user_id to add it to the table then full_name and so on. Do you have an idea how to do that? – tareklk Nov 01 '20 at 14:34
  • 1
    see this answer, this runs over all result rows and show also a html code that goes with it https://stackoverflow.com/a/51064538/5193536 you have this often, you want to program an idea and you never find the exact resolution, yu have to take what you find and adapt it to your needs – nbk Nov 01 '20 at 14:51

0 Answers0