1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Problem with a query

Discussion in 'XenForo Development Discussions' started by Robust, Sep 17, 2016.

  1. Robust

    Robust Well-Known Member

            $groupPairs = $this->_getDb()->fetchPairs('
            SELECT group_id, group_name
            FROM apms2_group
            WHERE group_id IN (?)
            ', $groups);
    This returns the first pair only.

    $groups is '1,2'

    If I replace IN (?) with IN (1,2) (for testing) it works properly and fetches multiple pairs. But if I use a prepared statement ($groups is also 1,2) it returns the first value only.

    I've tried Zend_Debug::dump to ensure $groups is correct, it is.

    Also doesn't work with:
    WHERE group_id IN (' . $this->_getDb()->quote($groups) . ')
  2. SneakyDave

    SneakyDave Well-Known Member

    Robust likes this.
  3. Mike

    Mike XenForo Developer Staff Member

    You need to split this to turn it into an array and then use the quote() method you gave as your final example.
    Robust likes this.
  4. Robust

    Robust Well-Known Member

    Thanks Mike. I'll try that out.

Share This Page