简体   繁体   English

使用节点 js/javascript 在 HTML 表中显示来自 SQL 数据库的数据

[英]Display data from a SQL database in an HTML table using node js/javascript

So I have created an HTML file and it has a table with several columns in it.所以我创建了一个 HTML 文件,它有一个包含几列的表格。 What I need to do is to find a way to display data from my SQL database into this HTML table.我需要做的是找到一种方法将我的 SQL 数据库中的数据显示到这个 HTML 表中。 I have created a connection with the database using Node, but I have no idea how to display the data in the table.我已经使用 Node 创建了与数据库的连接,但我不知道如何在表中显示数据。 I have been looking everywhere but all I can find is PHP code, and I do not want to use it.我到处找,但我只能找到 PHP 代码,我不想使用它。 I need it to be in Node.我需要它在 Node.js 中。 How should I start this?我该如何开始? Thank you all.谢谢你们。 Here is what I have so far regarding the HTML:到目前为止,这是我对 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.关于 Javascript 文件,我已经创建了一个与 Azure 数据库的连接和一个用于从中检索数据的 SELECT 查询。 Now, I just need to put the data that I have inside the HTML table above.现在,我只需要将我拥有的数据放在上面的 HTML 表格中。

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: 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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在hbs / html文件Node.Js中显示来自数据库的数据(使用mongodb) - Display data from database (using mongodb) in hbs/html file Node.Js 如何将数据从SQL数据库显示到PHP / HTML表中 - How to display data from SQL database into PHP/HTML table 如何使用 node.js 将 sql 中的数据放入 html 的表中 - How to put data from sql into a table in html using node.js 如何使用 javascript 从 html 表中删除 firebase 数据库节点? - How to delete firebase database node from html table using javascript? 使用 Node.js 在 HTML 上显示来自数据库的数据 - Display data from db on HTML using Node.js 使用javascript从数据库中检索多个行并显示在html表中 - Retrieving multiple Rows from database using javascript and display in an html table 如何从mongodb获取数据并使用节点js将其显示在表中? - how to fetch data from mongodb and display it in a table using node js? 使用节点 js 通过搜索按钮将数据从数据库检索到 html - retrieve data from database into html using node js by search button 在输入属性更改时使用Javascript使用SQL数据库中的数据实时更新HTML表 - Live updating HTML table using Javascript on input property change with data from SQL database 如何使用javascript和node.js-mysql而不使用php将HTML表单数据提交到MySql数据库表中? - How can I submit HTML form data into MySql database table using javascript along with node.js - mysql and without php?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM