2

I have a Request table that has some columns. I need to select a row in the table and then use a specific column value(say request_initiator) to search it in another table.

connection.query('SELECT * FROM Requests WHERE `request_id` = ?', req.body.id, function(error,results, fields){}

My results gives me multiple objects which then contains the component elements with different value.

0   
request_id  1
user_id "user1"
from    "[email protected]"
to  "owner2"
status  "deleted"
1   
request_id  2
user_id "user4"
from    "[email protected]"
to  "owner2"
status  "pending"    

I have to access results to get from and then search it in Owners table.

However, results.from doesn't give anything. results[0] gives the first object but I can't access the elements of that list

How should I proceed with this?

8
  • results[0].from? Commented Jun 12, 2019 at 8:28
  • @TheMaster it gives undefined Commented Jun 12, 2019 at 8:29
  • Provide result of console.log(JSON.stringify(results[0])) Commented Jun 12, 2019 at 8:30
  • {"Request_id":1,"user_id":"user1","from":"[email protected]","to":"owner2","status":"deleted"} Commented Jun 12, 2019 at 8:33
  • 1
    I don't get it. Then results[0].from should've worked. May be console.log(results[0]["from"]) Commented Jun 12, 2019 at 8:39

1 Answer 1

2

results is a array of multiple objects. You can access the from key's value using

results[0]["from"]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.