How to create a query to two different tables and render them in the same view with Node js Express

0

Good afternoon, my name is Diego Castaño, I am new to this community and I need a favor from some of you.

In a view (vConfExit.jade) I have two select and I need to fill them with two different tables that I have in a database, I have managed to fill one of them with the following code, but to fill the second select I do not know how to create the query within that same code.

getConfSalida: function(req,res,next){
      var config=require('.././database/config');
      var db=mysql.createConnection(config);
      db.connect();
      var sql=("SELECT * FROM tbl_conductor");
      var result=null;
      db.query(sql, function(err,rows,fields){
      result=rows;
      db.end();
      res.render('products/vConfSalida',{result: result});    
      });
},

Can someone please tell me how to do it?

thank you very much

Diego Castaño

    
asked by Diego Castaño 23.11.2017 в 20:48
source

1 answer

0

Did you try something like this?

getConfSalida: function(req,res,next){
  var config=require('.././database/config');
  var db=mysql.createConnection(config);
  db.connect();
  var sql=("SELECT * FROM tbl_conductor");
  var sql2=("SELECT * FROM tabla");
  var result=null, result2=null;
  db.query(sql, function(err,rows,fields){
    result=rows;
    db.query(sql2, function(err, rows, fields) {
       result2=rows
    })
    db.end();
    res.render('products/vConfSalida',{result: result, result2: result2});    
  });
},
    
answered by 13.12.2017 в 03:01