Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

hello guys i found some similar questions here but nothing work's for me maybe someone can help me. i have a couple of filter where the user can list other users by properties like in a dating site. i want to show the user just the members from the filters the user choose. i store the keywords in an array and want to get the data now from two different tables. at the moment i use this query but its just shows me the values from one table

$sql = "SELECT * FROM users WHERE username IN ($data) AND country IN ($data) OR city IN ($data) OR gender IN ($data)";  

i need to get some more properties like smoker or non smoker etc. from another table how would i do this with this array ($data). sorry for the bad english

the table one is users who contains id, username, gender, country and the other table called properties who contains id, userid, hobbies, jobs i need to join them somehow

share|improve this question
2  
Show us your other tables and columns, it will be easier. – kmas Dec 12 '13 at 21:00
    
What is the value of $data? – Dave Dec 12 '13 at 21:33
    
the value of $data is depending on users choice for example france,footbal,male,......,....... or just football,male the user should find people by his search results – user3097100 Dec 12 '13 at 21:54
    
Write all your php code if you want some help. – kmas Dec 12 '13 at 23:04
    
thanks its working now with a bit of modifying based on your code thank you – user3097100 Dec 12 '13 at 23:18
up vote 0 down vote accepted

Use JOIN on their "linked" column :

$sql  = " SELECT u.username, u.country  ";
$sql .= " FROM users u ";
$sql .= " LEFT OUTER JOIN other_table t ON u.id = t.id";
$sql .= " WHERE username IN ($data) AND country IN ($data) OR city IN ($data) OR gender IN ($data)"; 

MySQL documentation.

share|improve this answer
    
thanks for the quick reply but i get just Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in... i edit my question. thanks anyway – user3097100 Dec 12 '13 at 21:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.