SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Location
    London, UK
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    zend framework select where not working

    I have the following that is to fetch only records that have the field "loan_cycle_number" = 0; yet it still fetches all the records. I have googled all I can and still no solution found:

    Code:
            
            $groups = new Application_Model_GroupsMapper();
            $db = $groups->getDbTable()->select();
            $select->where('loan_cycle_number = ?', 0);
    
            $rows = $groups->fetchAll($select);
    the getDbTable method is like so

    Code:
        public function getDbTable()
        {
            if (null === $this->_dbTable) {
                $this->setDbTable('Application_Model_DbTable_Groups');
            }
            return $this->_dbTable;
        }
    Thanks
    Prov. 13:20 - He that walketh with wise men shall be wise: but a
    companion of fools shall be destroyed

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    What is the straight SQL statement that brings back the result you want?

    (using whatever you manage your dbase with, PhpMyAdmin etc)

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Location
    London, UK
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well its
    Code:
    SELECT registration_date FROM groups WHERE loan_cycle_number =  0;
    Prov. 13:20 - He that walketh with wise men shall be wise: but a
    companion of fools shall be destroyed

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Have you checked the actual SQL query that your code generates/executes? According to the docs, you should be doing something similar to...*

    PHP Code:
    <?php
    $groups 
    = new Application_Model_GroupsMapper;
    $rows $groups->getDbTable()->fetchAll(
        
    $groups->getDbTable()->select()->where('loan_cycle_number = ?'0)
    );
    ?>
    *I've never used ZF, so maybe wrong.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    I'm wondering if this isn't a reserved words issue?

    Group is in Mysql, maybe Groups is in the ZF mapper?

    Sorry, for this long shot, but I don't know enough about this package either.

  6. #6
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Location
    London, UK
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks all. I swapped my code with Anthony's and it works now. Apart from the error having this
    Code:
           $db = $groups->getDbTable()->select();
    instead of
    Code:
           $select = $groups->getDbTable()->select();
    in the code I posted earlier, I think both codes should work but my doesn't and Anthony's does. Any way thanks for your help am happy now
    Prov. 13:20 - He that walketh with wise men shall be wise: but a
    companion of fools shall be destroyed


Bookmarks

Posting Permissions

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