2

So I have created an HTML file and it has a table with several columns in it. What I need to do is to find a way to display data from my SQL database into this HTML table. I have created a connection with the database using Node, but I have no idea how to display the data in the table. I have been looking everywhere but all I can find is PHP code, and I do not want to use it. I need it to be in Node. How should I start this? Thank you all. Here is what I have so far regarding the HTML:

    <div id="table">
        <table align="right" cellspacing="0" cellpadding="5">
            <tr>
                <th>Match </th>
                <th>Time</th>
                <th>Red 1</th>
                <th>S</th>
                <th>Red 2</th>
                <th>S</th>
                <th>Red 3</th>
                <th>S</th>
                <th>Blu 1</th>
                <th>S</th>
                <th>Blu 2</th>
                <th>S</th>
                <th>Blu 3</th>
                <th>S</th>
                <th>Red Sc</th>
                <th>Blu Sc</th>
            </tr>
        </table>
    </div>

Regarding the Javascript file, I have created a connection with the database from Azure and a SELECT query for retrieving data from it. Now, I just need to put the data that I have inside the HTML table above.

3
  • Have you already made routes from nodejs? Commented Jan 24, 2020 at 2:55
  • If you could post a minimal, reproducible example of your code to help us start with something, it could help us help you. Commented Jan 24, 2020 at 3:07
  • Oh, I have just added what I have so far. Commented Jan 25, 2020 at 15:34

1 Answer 1

1

Just an example, you'll get the idea.

Nodejs:

var express = require('express')
var app = express()

app.get('/getData', function(req, res) {
    ... // Get data from database
})

html:

<table>
  <thead>
    <th>id</th>
    <th>name</th>
  </thead>
  <tbody id="place-here"></tbody>
</table>
<script>
  $.get('/getData', {}, function(result) {
    let res = '';
    result.forEach(data => {
      res += `<tr><td>${data.id}</td><td>${data.something}</td></tr>`
    })
    $('#place-here').html(res)
  });
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.