timmah1 Posted March 31, 2009 Share Posted March 31, 2009 I'm not sure the correct way to do this or to word this. I need to be able to select everything posted from myself and from people that I'm subscribed to. I tried JOINS, but I do not get the results I need, so I remember someone before showing me a different way, but all I keep getting are results for me, not from who i subscribe to as well. Here is my code <?php $query2 = "SELECT * FROM users1 WHERE userid = '$user'"; $result2 = mysql_query($query2); $p2 = mysql_fetch_assoc($result2); $follower = $p2['followers']; $me = $p2['userid']; //Grab all posts from user, and from their subscribers $query = "SELECT * FROM posts WHERE userid = '$follower'"; $query = "SELECT * FROM posts WHERE userid = '$me' ORDER BY posted DESC"; $result = mysql_query($query); while($p = mysql_fetch_assoc($result)){ $posted = date("F j, Y g:i a", strtotime($p['posted'])); $going = $p['going']; $city = $p['city']; $state = $p['state']; $p_user = $p['userid']; $p_folow = $p['followers']; ?> Basically, I need to grab all posts from $me and from $follower. Can anybody show me the correct way? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/151997-solved-query-problem/ Share on other sites More sharing options...
Maq Posted April 1, 2009 Share Posted April 1, 2009 Why can't you just do this? $query = "SELECT * FROM posts WHERE userid = '$follower' OR userid = '$me' ORDER BY posted DESC"; Quote Link to comment https://forums.phpfreaks.com/topic/151997-solved-query-problem/#findComment-798238 Share on other sites More sharing options...
timmah1 Posted April 1, 2009 Author Share Posted April 1, 2009 Because it has to grab both I tried this $query = "SELECT * FROM posts WHERE userid = '$follower' AND userid = '$me' ORDER BY posted DESC"; But I get no results then Quote Link to comment https://forums.phpfreaks.com/topic/151997-solved-query-problem/#findComment-798247 Share on other sites More sharing options...
Maq Posted April 1, 2009 Share Posted April 1, 2009 Yeah, you need to use OR. userid can't be 2 different numbers at the same time, you know what I mean? Quote Link to comment https://forums.phpfreaks.com/topic/151997-solved-query-problem/#findComment-798248 Share on other sites More sharing options...
timmah1 Posted April 1, 2009 Author Share Posted April 1, 2009 I understand that. I can't use OR, because then it's only going to grab everything from either or, I need it to be both. But I need to try and be able to pull all of the posts from the users is, as well as the follower id. Quote Link to comment https://forums.phpfreaks.com/topic/151997-solved-query-problem/#findComment-798262 Share on other sites More sharing options...
timmah1 Posted April 1, 2009 Author Share Posted April 1, 2009 I got it to work with the OR, I didn't realize that would work Thanks for your help Maq. Quote Link to comment https://forums.phpfreaks.com/topic/151997-solved-query-problem/#findComment-798263 Share on other sites More sharing options...
Maq Posted April 1, 2009 Share Posted April 1, 2009 I got it to work with the OR, I didn't realize that would work Thanks for your help Maq. Hehe, sure buddy. Don't worry, I always get confused with logical operators Quote Link to comment https://forums.phpfreaks.com/topic/151997-solved-query-problem/#findComment-798270 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.