使用Node.js和MySQL进行多个复选框过滤

时间:2018-11-16 08:57:17

标签: javascript node.js checkbox

我正在使用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
       });
  });
});

MYSQL Table

0 个答案:

没有答案