一个按钮影响桌子
因此,我试图制作一个简单的页面,从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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论