Answer the question
In order to leave comments, you need to log in
How to change the display (newer ones first) to data pages from the database?
Good afternoon everyone, I noticed a very upsetting fact, my data is displayed first old then new, I would like to change the display order, that is, the data that appeared in the database (those with id greater in value) were displayed on top.
Here is my code (simplified as much as possible, but the essence is the same)
ejs file
<% for(var i = 0; i < result.length; i++) {%>
<div><%=result[i].dataValues.username%></div><br>
<%}%>
файл роута
router.get('/index', (req, res) => {
let result = User.findAll({
offset: 0, limit: 10
}).then(result => {
res.render('index', {result: result});
console.log(result);
})
const User = db.define('table', {
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
primaryKey: true,
},
username: {
type: Sequelize.STRING(254)
},
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question