1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Rep Power

    Selecting for posts from matching userIds

    I have a subscription system where users can subscribe to different users and then grab their posts if they are in the subscription array which consist of user ids.

    I can't figure out a way to grab posts only from the ones in the user's subscriptions and then ORDER BY submission date limiting to a certain amount.

    Here's what I have so far which doesn't work

    $subscriptionsQuery = '';
    foreach($subscriptions as $userId) {
    	$subscriptionsQuery .= " ".$userId;
    $query = "SELECT id FROM posts WHERE MATCH userId AGAINST ('".$subscriptionsQuery."' IN BOOLEAN MODE) ORDER BY submitted DESC LIMIT 20";
    This doesn't work since userId is BIGINT but I'm trying to acheive something similar to this

    EDIT: Figured it out. Discovered the usage of IN
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2008
    Rep Power
    SELECT id 
      FROM posts 
     WHERE userId IN($subscriptionsQuery) 
        BY submitted DESC LIMIT 20;

    (assuming your array looks something like this:


IMN logo majestic logo threadwatch logo seochat tools logo