我正在使用Node JS和Mysql处理复选框过滤器。但是,我很难过。我想做的是,我要显示用户检查的类别(科学,技术,教育)。
在我的ejs文件中,我有以下代码:
<div class="custom-control custom-checkbox custom-control-inline">
<input type="checkbox" name ="Science" class="custom-control-input" id="science-cat" value ="science" >
<label class="custom-control-label" for="defaultInline1">Science</label>
</div>
<div class="custom-control custom-checkbox custom-control-inline">
<input type="checkbox" name="Technology" class="custom-control-input" id="technology-cat" value="technology">
<label class="custom-control-label" for="defaultInline2">Technology</label>
</div>
<div class="custom-control custom-checkbox custom-control-inline">
<input type="checkbox" class="custom-control-input" id="education-cat" value="Education" onchange="location = this.value;">
<label class="custom-control-label" for="defaultInline3">Education</label>
</div>
在我的app.js文件中,我有以下代码:
app.get('/DownloadMaterials',function(req, res){
var sort = req.query.sort;
if(sort == null){
sort = "DESC";
}
var query = 'Select downloads.userId,steam_category.steamName,downloads.fileType,downloads.fileName,downloads.downloadDate,faculty.fName,faculty.lName from downloads LEFT JOIN faculty ON downloads.userId=faculty.facultyId LEFT JOIN steam_category ON downloads.categoryId=steam_category.steamId ORDER BY downloads.downloadDate '+sort+'';
db.query(query,function(err,result){
if(err){
throw err;
}
res.render('pages/DownloadMaterials.ejs',{
siteTitle: "Test",
pageTitle: "E-Learning Management System",
items: result
});
});
});