首页 > 解决方案 > 使用 nodejs 和 mysql 进行多个复选框过滤

问题描述

我正在使用 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 表

标签: javascriptnode.jscheckbox

解决方案


推荐阅读