Vanessa341 Vanessa341 - 4 years ago 172
MySQL Question mysql two and clauses

I'm using with node-mysql module.kindly help in editing the code. How do i make this work?

var srecord = {m_from: data.usid, m_to:data.tid};
dbconn.query('SELECT m_from,m_text FROM messages WHERE (m_from = ? AND m_to = ?) OR (m_to = ? AND m_from = ?)',[data.usid,data.tid],function(err, records){
if(err) throw err;

if executed, it shows error: check the manual that corresponds to ur DB server for right syntax to use near '? AND m_from=?)'

Answer Source

I did it on my own after much headache...The solution was pretty simple...the num of placeholders was not equal to the num of i re-added the same parameters again.. like this:

dbconn.query('SELECT m_from,m_text FROM messages WHERE (m_from=? AND m_to=?) OR (m_to=? AND m_from=?)',[data.usid,data.tid,data.usid,data.tid]

Hope it helps sum1!! :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download