Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
72 views
in Technique[技术] by (71.8m points)

javascript - sql query not getting data nodejs

I have a function where I select the rows from my divisions table, and then select the product from the other table. however it works for the selecting the product, the divisions don't show up. I have this function here:

   var getDivision = "select * from DIVISIONS";
    ibmdb.open(req.session.ibmdbconnDash, function (err, conn) {
    if (err) return console.log(err);
    conn.query(getDivision, function (err, rows) {
      if (err) {
        console.log(err);
      }
      console.log("divisions: " + rows)

  conn.close(function () {
    console.log("closed the function p1 /editProduct");
  

var editProduct =
  "SELECT * FROM PRODUCTS where ITEM = '" + req.query.item + "'";
ibmdb.open(req.session.ibmdbconnDash, function (err, conn) {
  if (err) return console.log(err);
  conn.query(editProduct, function (err, rows) {
    if (err) {
      console.log(err);
    }

    res.render("editProduct", {
      page_title: "editProduct",
      data: rows,
     
      userName: req.session.username,
FN: req.session.firstname,
LN: req.session.lastname,
CO: req.session.company,
    });

    conn.close(function () {
      console.log("closed the function /editProduct");
    });
  });
});
  })

so on my front end (ejs) I have this:

 <label for="divisionCategory">CATEGORY (OPTIONAL):</label>
    <select name="category" id="">
    <% if(data.length){ 
      for(var i = 0;i < data.length;i++) { %>
       
          <option value="<%= data[i].CATEGORIES %>"><%= data[i].CATEGORIES %></option>
          
    <% }
  }else{ %>
  <% } %>
</select>

this should work, as I have the same thing running for another function, but for this one it is not working. please help!!!

question from:https://stackoverflow.com/questions/65829844/sql-query-not-getting-data-nodejs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...