Tell me more ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I'm having trouble with a specific query (PDO style) that selects 4 fields from a table with a simple condition : contact_type='a' , label_id = a value (number) and also it checks that the particular contact type ('a') is not blocked, meaning is not in myl_blocked_contacts table. I LEFT

$query = "SELECT myl_contacts.contact_id, mya_users.name, mya_users.city, mya_users.ext 
          from myl_contacts, mya_users, 
              LEFT JOIN myl_blocked_contacts 
          WHERE myl_contacts.contact_type='a' 
            AND myl_contacts.label_id=:id 
            AND (myl_blocked_contacts.contact_type!='a' 
             AND myl_blocked_contacts.contact_id!=mya_users.id)
         ";
                                            $result = $db->prepare($query);
                                            $result->bindValue(':id', $_id, PDO::PARAM_INT);
                                            $result->execute();
share|improve this question
3  
The query seems to have several syntax errors. And there is no condition for joining the two tables: myl_contacts and mya_users – ypercube Oct 8 '12 at 14:05
1  
And what's the question? – dezso Oct 8 '12 at 14:07
i don't know where I'm wrong...why does not the query work...where am I doing wrong...any help is appreciated...i managed to replace old mysql_num_rows and all old code to PDO::style and now i want to upgrade it as well, it took around 2 months to replace all code – Adrian Tanase Oct 8 '12 at 19:02
1  
@ypercube: even the join between myl_blocked_contacts and mya_users is not really a join. Adrian: how does the script not work? - is it parsing properly in an SQL editor (MySQL Admin, Mysql WorkBench)? Did you try it first in an editor or you want to use it directly from PHP? - does it throw an error in execution? - does it execute but it returns wrong data? You have to understand that we don't see your error message :-). – Marian Oct 13 '12 at 23:29
1  
I'm closing as this is too basic for dba anyway. It seems you had your answer with the first comment posted here, but it was spelled out on SO. – Jack Douglas Oct 31 '12 at 8:06
show 4 more comments

closed as off topic by Derek Downey, Nick Chammas, Paul White, ypercube, Jack Douglas Oct 31 '12 at 8:06

Questions on Database Administrators Stack Exchange are expected to relate to database administration within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

Browse other questions tagged or ask your own question.