"Mysql problem "个人资料数据未显示在我的 html 页面中
"Mysql problem "profile data do not show in my html page
我正在尝试查看来自 Mysql 的数据并将其传递到个人资料页面,在那里我可以看到用户的信息,但我尝试了很多次和不同的方法,但找不到方法,也在那里没有错误我用过 {{#each}}{{this.fullname}}{{/each}} 我也累了但是数据不显示有人能帮我解决这个问题或者如果有另一个显示我的数据的方式
我正在使用节点 js、express 和 hbs 引擎
router.get('/profilePage/:userid', function(req, res) {
var userid = req.params.userid;
pool.query('SELECT * from users where id = ?', userid, function(error, results, feilds) {
if (error) {
console.log("error ocurred while getting user details of " + userid, error);
res.send({
"code": 400,
"failed": "error ocurred"
});
} else {
res.render("profilePage",{user:results});
}
});
});
试试这个:
router.get('/profilePage/:userid', function(req, res) {
var userid = req.params.userid;
if (!userid) {
//No user id provided
} else {
pool.query('SELECT * from users where id = ?',
[userid],
(error, results, feilds)=> {
if (error) {
console.log("error ocurred while getting user details of " + userid, error);
res.send({
"code": 400,
"failed": "error ocurred"
});
} else {
if (results.length > 0) {
const profile = results[0]
//You can then access the user id with
console.log(profile.id)
res.render("profilePage",{user:profile});
} else {
console.log('unable to retrieve a profile')
}
}
});
}
});
我正在尝试查看来自 Mysql 的数据并将其传递到个人资料页面,在那里我可以看到用户的信息,但我尝试了很多次和不同的方法,但找不到方法,也在那里没有错误我用过 {{#each}}{{this.fullname}}{{/each}} 我也累了但是数据不显示有人能帮我解决这个问题或者如果有另一个显示我的数据的方式
我正在使用节点 js、express 和 hbs 引擎
router.get('/profilePage/:userid', function(req, res) {
var userid = req.params.userid;
pool.query('SELECT * from users where id = ?', userid, function(error, results, feilds) {
if (error) {
console.log("error ocurred while getting user details of " + userid, error);
res.send({
"code": 400,
"failed": "error ocurred"
});
} else {
res.render("profilePage",{user:results});
}
});
});
试试这个:
router.get('/profilePage/:userid', function(req, res) {
var userid = req.params.userid;
if (!userid) {
//No user id provided
} else {
pool.query('SELECT * from users where id = ?',
[userid],
(error, results, feilds)=> {
if (error) {
console.log("error ocurred while getting user details of " + userid, error);
res.send({
"code": 400,
"failed": "error ocurred"
});
} else {
if (results.length > 0) {
const profile = results[0]
//You can then access the user id with
console.log(profile.id)
res.render("profilePage",{user:profile});
} else {
console.log('unable to retrieve a profile')
}
}
});
}
});