Home > Software design >  Why is node js returning all tinyint data even though I select * where it is 0?
Why is node js returning all tinyint data even though I select * where it is 0?

Time:03-20

I tried the same sql command in phpmyadmin and it works fine but different in node js so I don't think it's a problem with the sql command.

  app.get('/tag/:id', (req, res) => {
    const id = req.params.id;
    
  
    console.log(id);
      connection.query("SELECT * from news   WHERE ? = 0",id, function (error, results, fields) {
        if (error) {
          console.log(error);
      }
      else {
            res.send(results) 
      };
  });
   
 })

When I use the

SELECT * from news WHERE ? = 0 

It will return all values.

But when I use

   SELECT * from news WHERE ? = 1

It doesn't return any values ​​at all.

This is my database structure. enter image description here enter image description here

CodePudding user response:

Are you trying to select to use which boolean field to select on? This can't be done using query parameters.

  • Related