squiblo Posted January 12, 2010 Share Posted January 12, 2010 I have never attempted mysql like this before...this is what the table looks like.. || user_id || other_person_id || friend || foe || 2 44 1 0 34 2 1 0 What i want to do is this.... say that the $_SESSION['user_id'] == 2 and $user_id = $SESSION['user_id']; Without doing 2 queries how can I pick put all the people that are friends with $user_id? Quote Link to comment https://forums.phpfreaks.com/topic/188263-query-problem/ Share on other sites More sharing options...
squiblo Posted January 12, 2010 Author Share Posted January 12, 2010 I guess it would be a little like this with a few changes... mysql_query("SELECT * FROM user_id AND other_person_id WHERE user_id='$user_id' AND other_person_id='$user_id'"); Quote Link to comment https://forums.phpfreaks.com/topic/188263-query-problem/#findComment-993896 Share on other sites More sharing options...
squiblo Posted January 12, 2010 Author Share Posted January 12, 2010 i came up with this, but im not sure... SELECT * FROM user_id AND page_zebra WHERE user_id='$user_id' AND page_zebra='$user_id' Quote Link to comment https://forums.phpfreaks.com/topic/188263-query-problem/#findComment-993905 Share on other sites More sharing options...
squiblo Posted January 12, 2010 Author Share Posted January 12, 2010 forget that previous post, thats just be being stupid once again...i think i ment this... mysql_query("SELECT * FROM table_name WHERE user_id='$user_id' OR page_zebra_id='$user_id' AND friend=1"); i have tried this but it only give me data from 1 row Quote Link to comment https://forums.phpfreaks.com/topic/188263-query-problem/#findComment-993934 Share on other sites More sharing options...
aebstract Posted January 13, 2010 Share Posted January 13, 2010 mysql_query("SELECT * FROM table WHERE user_id = $user_id AND friend = '1'"); Quote Link to comment https://forums.phpfreaks.com/topic/188263-query-problem/#findComment-993951 Share on other sites More sharing options...
squiblo Posted January 13, 2010 Author Share Posted January 13, 2010 Thank, but i also what to select all from where other_person_id = '$user_id' Quote Link to comment https://forums.phpfreaks.com/topic/188263-query-problem/#findComment-993954 Share on other sites More sharing options...
squiblo Posted January 13, 2010 Author Share Posted January 13, 2010 an easier way of putting it, how can i merge these 2 queries into 1... mysql_query("SELECT * FROM table WHERE user_id='$user_id' AND friend=1"); and mysql_query("SELECT * FROM table WHERE other_person_id='$user_id' AND friend=1"); and then my aim is to echo out the the row that doesnt have $user_id in it NOTE: $user_id will never been the same in both rows Quote Link to comment https://forums.phpfreaks.com/topic/188263-query-problem/#findComment-993957 Share on other sites More sharing options...
fenway Posted January 16, 2010 Share Posted January 16, 2010 You can use an OR. Quote Link to comment https://forums.phpfreaks.com/topic/188263-query-problem/#findComment-996189 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.