m4x3vo Posted July 10, 2009 Share Posted July 10, 2009 I have a table named user_ach and it has the columns user_id and ach_id. How can I find the ach_id's that two user_id's have in common? Quote Link to comment https://forums.phpfreaks.com/topic/165528-need-some-help/ Share on other sites More sharing options...
rhodesa Posted July 10, 2009 Share Posted July 10, 2009 For users 1 and 2 it should be something like: SELECT a.ach_id FROM user_ach a INNER JOIN user_ach b ON a.ach_id = b.ach_id AND a.user_id = 1 AND b.user_id = 2 Quote Link to comment https://forums.phpfreaks.com/topic/165528-need-some-help/#findComment-873079 Share on other sites More sharing options...
m4x3vo Posted July 11, 2009 Author Share Posted July 11, 2009 Nah didnt work ??? Quote Link to comment https://forums.phpfreaks.com/topic/165528-need-some-help/#findComment-873800 Share on other sites More sharing options...
haku Posted July 12, 2009 Share Posted July 12, 2009 It should have - let's see your query. Quote Link to comment https://forums.phpfreaks.com/topic/165528-need-some-help/#findComment-873810 Share on other sites More sharing options...
m4x3vo Posted July 12, 2009 Author Share Posted July 12, 2009 Ah it did work. Is there a way to simplify my code, I want the query inside the while statement ($querytt) to be joined in the same query outside the statement ($queryt)... both user_ach and ach can be joined on ach_id and id... gah i know the code is messy xD $queryt = "SELECT a.ach_id FROM user_ach a INNER JOIN user_ach b ON a.ach_id = b.ach_id AND a.user_id = 1 AND b.user_id = 15"; $resultt = mysql_query($queryt) or die(mysql_error()); while ($kkk = mysql_fetch_assoc($resultt)){ $lol = $kkk['ach_id']; $querytt = "SELECT * FROM ach WHERE id = '$lol'"; $resulttt = mysql_query($querytt) or die(mysql_error()); $kkkk = mysql_fetch_assoc($resulttt); $image = $kkkk['image']; echo "<img src='$image'></img>"; } Quote Link to comment https://forums.phpfreaks.com/topic/165528-need-some-help/#findComment-873860 Share on other sites More sharing options...
m4x3vo Posted July 12, 2009 Author Share Posted July 12, 2009 lol this is still bugging me xD Quote Link to comment https://forums.phpfreaks.com/topic/165528-need-some-help/#findComment-874261 Share on other sites More sharing options...
rhodesa Posted July 13, 2009 Share Posted July 13, 2009 should be something like this: $queryt = "SELECT c.image FROM user_ach a INNER JOIN user_ach b ON a.ach_id = b.ach_id LEFT JOIN ach c ON a.ach_id = c.id WHERE a.user_id = 1 AND b.user_id = 15 "; $resultt = mysql_query($queryt) or die(mysql_error()); while($kkk = mysql_fetch_assoc($resultt)){ $image = $kkk['image']; echo "<img src='$image'></img>"; } Quote Link to comment https://forums.phpfreaks.com/topic/165528-need-some-help/#findComment-874504 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.