Reputation: 11
When i connect with mysql ,i get this value { id: 14 } actually i wanna get only 14 this is my code
app.get('/register',function(req,res){
var data = {
"error":1,
"result":""
};
console.log("ams");
connection.query("SELECT id from register",function(err, rows, fields){
if(rows.length != 0){
data["error"] = 0;
data["result"] = rows;
res.json(data);
console.log(data.result[0]);
}else{
data["result"] = 'No data Found..';
res.json(data);
}
});
});
Upvotes: 0
Views: 81
Reputation: 73291
If you're expecting one row only, you could set
data["result"] = rows[0].id;
However, your response is an array of json objects no matter how many results you get. It's much better to setup the res.json()
receiver to work with objects, not plain strings/numbers.
It is not possible to get only values as a mysql query result in node with node-mysql (and I don't think there's any other library that would do that, because it doesn't make sense).
Upvotes: 1