一个按钮影响桌子

发布于 2025-01-22 14:18:02 字数 1391 浏览 2 评论 0原文

因此,我试图制作一个简单的页面,从MySQL表中检索并呈现一个表格,但是我无法理解如何只使用一个按钮更改表,例如按下按下时,按下时,按下时,该按钮会发送以下查询(例如,活动订单从订单表):

SELECT * FROM foo WHERE (condition);

然后是一个具有此查询的第二个按钮(例如,从订单表中完成订单):

SELECT * FROM foo WHERE (different condition);

我将Handlbars用作带有Express和Nodejs的模板引擎来处理其余的引擎。这是我到目前为止尝试的:

我尝试使用路线来影响我的表格类似于搜索的工作方式,但没有实际搜索任何东西。

按钮

<a href="/completed.hbs"> Completed Orders </a>

user.js:

router.get('/completed', userController.complete);

我试图致电

exports.complete = (req, res) => {
  connection.query('SELECT * FROM orders WHERE deleted = 0 AND stat = "Completed"', (err, rows) => {
    if (!err) {
      res.render('home', { rows });
    } else {
      console.log(err);
    }
    console.log('The data from user table: \n', rows);
  });
}

循环显示行

    {{#each rows}}
    <tr>
      <th scope="row">{{this.id}}</th>
      <td>{{this.name}}</td>
      <td>{{this.contact}}</td>
      <td>{{this.address}}</td>
      <td>{{this.food}}</td>
      <td>{{this.stat}}</td>
    </tr>
    {{/each}}

对不起,如果这是一个愚蠢的问题,但是我对节点JS和所有这些后端的东西都是新手。

So, im trying to make a simple page that retrieves and renders a table from mysql table, but I cant understand how I can just use one button to change the table, such as a button that when pressed sends the following query (e.g active orders from a table of orders):

SELECT * FROM foo WHERE (condition);

And then a second button that has this query (e.g completed orders from a table of orders):

SELECT * FROM foo WHERE (different condition);

I'm using handlbars as my templating engine with express and nodejs to handle the rest. Here's what I tried so far:

I tried using routes to affect my table similar to how search works, but without actually searching for anything.

The Button

<a href="/completed.hbs"> Completed Orders </a>

User.js:

router.get('/completed', userController.complete);

Function I'm trying to call

exports.complete = (req, res) => {
  connection.query('SELECT * FROM orders WHERE deleted = 0 AND stat = "Completed"', (err, rows) => {
    if (!err) {
      res.render('home', { rows });
    } else {
      console.log(err);
    }
    console.log('The data from user table: \n', rows);
  });
}

loop to display rows

    {{#each rows}}
    <tr>
      <th scope="row">{{this.id}}</th>
      <td>{{this.name}}</td>
      <td>{{this.contact}}</td>
      <td>{{this.address}}</td>
      <td>{{this.food}}</td>
      <td>{{this.stat}}</td>
    </tr>
    {{/each}}

Sorry if this is a stupid question, but I'm fairly new to node js and all this backend stuff.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文