'One button to affect a table
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
