Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-13-2007, 02:11 AM
Member
 
Join Date: Nov 2007
Posts: 33
Question Obtaing A Single Model Instance Based On SQL Constraint

Hi, why doesn't the following return a rowset containing one row? In short, I have a model called Animal and I would like to get a row based on a constraint:

PHP Code:
function updateAction() {

        
$this->view->title "Update Animal";

        
$episode = new Animal();
        
$sql "SELECT * FROM animals WHERE is_rare = 1 ORDER BY id DESC LIMIT 1";
        
$this->view->currentAnimal $animal->fetchAll$sql );

      } 

Last edited by conradwt : 12-13-2007 at 02:28 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 12-13-2007, 07:41 AM
Junior Member
 
Join Date: Oct 2007
Posts: 16
Default

$this->view->currentAnimal is a rowset object, because fetchAll() always returns a rowset, even if only one row is found. You can use current() on the rowset to fetch the single row.
Or use fetchRow() on the table instead, because it returns the first row returned by the query.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:59 AM.