Issue
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
Solution
Are you trying to select to use which boolean field to select on? This can’t be done using query parameters.
Answered By – Vesa Karjalainen
Answer Checked By – Katrina (BugsFixing Volunteer)