exports.post = function(req, res){
var obj = {};
var eacode = req.body.eacode;
db.all("SELECT * FROM localarea_listings WHERE eacode= ? ",eacode, function(err,rows2){
rows2.forEach(function (row2) {
var hcn = row2.hcn;
var shsn = row2.shsn;
console.log(hcn);
console.log(shsn);
});
db.all("UPDATE localarea_listings SET INTERVIEW_STATUS = ? WHERE eacode = ?
and hcn =? and shsn = ?",[req.body.INTERVIEW_STATUS, req.body.eacode,
req.body.hcn, req.body.shsn],function(err,rows){
if (err)
{
console.log("Error Updating : %s ",err );
}
else
console.log("Success updating localarea_listings");
});
});
};
数据将根据数据库localarea_listings.db
中的变量eacode进行处理让我们说值hcn分别为1,2,3,4,5和shsn分别为6,7,8,9,10。
当我打印hcn和shsn时,该值将显示我想要的内容,即 hcn = [1,2,3,4,5]和shsn = [6,7,8,9,10]
问题将从这里开始,当我更新它时,它只更新数组的第一个值,对于hcn为1,对于shsn为6。我尝试使用row2 [0] .hcn和row2 [0] .shsn但它会导致错误..
我希望我的问题很明确。谢谢!
答案 0 :(得分:1)
您需要在forEach
中移动更新
exports.post = function(req, res) {
var obj = {};
var eacode = req.body.eacode;
db.all("SELECT * FROM localarea_listings WHERE eacode= ? ", eacode, function(err, rows2) {
rows2.forEach(function(row2) {
var hcn = row2.hcn;
var shsn = row2.shsn;
console.log(hcn);
console.log(shsn);
db.all("UPDATE localarea_listings SET INTERVIEW_STATUS = ? WHERE eacode = ? and hcn = ? and shsn = ? ",[req.body.INTERVIEW_STATUS, req.body.eacode, hcn, shsn], function(err, rows) {
if (err) {
console.log("Error Updating : %s ", err);
} else
console.log("Success updating localarea_listings");
});
});
});
};