Results 1 to 7 of 7

Thread: WHERE IN statement

  1. #1
    risoknop is offline Junior Member
    Join Date
    Jan 2009
    Posts
    26

    Default WHERE IN statement

    Hello,

    Is it possible to use WHERE IN or WHERE BETWEEN instead of simple WHERE in Zend_Db_Table?

    I have tried for example:

    [php]
    public function editMore(array $ids, array $data)
    {
    $ids = implode($ids, ', ');
    return $this->update($data, $this->getAdapter()->quoteInto('id IN (?)', $ids));
    }
    [/php]
    Where $ids looks like array(1, 2, 3) for example. And it didn't work.
    Last edited by risoknop; 02-21-2009 at 01:08 PM.

  2. #2
    risoknop is offline Junior Member
    Join Date
    Jan 2009
    Posts
    26

    Default

    Any ideas? The following doesn't work either:

    [php]
    public function editMore(array $ids, array $data)
    {
    $ids = implode($ids, ', ');
    $ids = '(' . $ids . ')';
    return $this->update($data, $this->getAdapter()->quoteInto('id IN ?', $ids));
    }
    [/php]

  3. #3
    risoknop is offline Junior Member
    Join Date
    Jan 2009
    Posts
    26

    Default

    Solved... I have figured it out

  4. #4
    donarb is offline Junior Member
    Join Date
    Aug 2008
    Posts
    7

    Default

    How about sharing your solution with the rest of the group? That way, others who come later may not have to ask the same question.

  5. #5
    SirAdrian's Avatar
    SirAdrian is offline Member
    Join Date
    Apr 2008
    Posts
    87

    Default

    There are tons of ways you can do this... here's one:[php]public function editMore(array $ids, array $data)
    {
    $ids = implode(array_map('intval', $ids), ',');
    return $this->update($data, "id in ($ids)");
    } [/php]

  6. #6
    gentlemich is offline Junior Member
    Join Date
    Jan 2009
    Posts
    19

    Default

    WHERE IN is a great solution but it only works with numbers.

    I wanted it to work with chars too but it's not the case...

  7. #7
    Tekerson is offline Senior Member
    Join Date
    Jul 2008
    Posts
    288

    Default

    It does work with other types, you just need to make sure you quote all the values in the list.
    Brenton Alker
    PHP Developer - Brisbane, Australia

    blog.tekerson.com | twitter.com/tekerson | brenton.mp

Similar Threads

  1. [Zend Lucene API] OR statement
    By Vojvoda in forum Mail, Formats & Search
    Replies: 0
    Last Post: 06-25-2010, 06:43 PM
  2. Prepared Statement ? vs :name
    By rsn1576 in forum Databases
    Replies: 0
    Last Post: 02-09-2010, 09:41 PM
  3. Echo an insert statement?
    By hogsolo in forum General Q&A on Zend Framework
    Replies: 2
    Last Post: 06-03-2009, 02:07 AM
  4. Zend_DB ON DUPLICATE KEY statement
    By juliovedovatto in forum General Q&A on Zend Framework
    Replies: 1
    Last Post: 03-02-2009, 07:24 AM
  5. Replies: 2
    Last Post: 09-02-2008, 06:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •