vendredi 16 novembre 2018

Multiple checkbox filtering with nodejs and mysql

I am working with a checkbox filter using Node JS and Mysql. However, I am having a hard time with it. What I want to do is that, I want to display the categories(Science, Technology, Education) that are checked by the user.

In my ejs file, I have this code:

<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>

In my app.js file, I have this code:

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




Aucun commentaire:

Enregistrer un commentaire