How to put a condition on a query in my custom module, i am executing a query. 

global $user;
$id = $user-&gt;uid;
print_r($id);
$query = db_query('SELECT n.nid, c.uid, n.title, f.body_value, fm.uri
FROM challenges c
LEFT JOIN node n ON n.nid = c.cid
LEFT JOIN field_data_body f ON n.nid = f.entity_id
LEFT JOIN field_data_field_challenge_pic fp ON n.nid = fp.entity_id
LEFT JOIN file_managed fm ON fp.field_challenge_pic_fid = fm.fid ');
**// WHERE c.cid = $id ');** 


when the where clause is commented out the query runs fine. I check it using:

foreach($query as $q)
{
            print_r($q);
}


But when i add the where clause i get an error: Syntax error or access violation...on the line where i write the where clause. How can i achieve this. Thanks
Clive's comment is right.  You should understand the reasons why, however,  I will give you the short answer ;)

Use db_select()

$query = db_select('challenges', 'c');
$query-&gt;fields('c');
$query-&gt;condition('c.cid', $id, '='); 
$result = $query-&gt;execute();