Quantcast

Zend_Db_Table_Abstract

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Zend_Db_Table_Abstract

Thomas List

Hi,

I am trying to return the max value of a row in my database.  The code I used is as follows:  

 public function getMaxLogId()
     {
          return $this->fetchAll(
            $this->select()
                ->from($this, array(new Zend_Db_Expr('max(log_id) as log_id')))
      );
       
     }

which returns an object.  How do I convert the object to an integer?  

I don't really see anything concrete in the discussion groups and it's really frustrating.  

Regards,
Thomas
     
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

RE: Zend_Db_Table_Abstract

Jachim Coudenys
Hi,

You might have a look at fetchOne() instead of fetchAll().

Then you can do return (int) $this->fetchOne(...);

Regards,
Jachim Coudenys

-----Oorspronkelijk bericht-----
Van: Thomas List [mailto:[hidden email]]
Verzonden: dinsdag 5 april 2011 21:17
Aan: [hidden email]; [hidden email]
Onderwerp: [fw-mvc] Zend_Db_Table_Abstract


Hi,

I am trying to return the max value of a row in my database.  The code I used is as follows:  

 public function getMaxLogId()
     {
          return $this->fetchAll(
            $this->select()
                ->from($this, array(new Zend_Db_Expr('max(log_id) as log_id')))
      );
       
     }

which returns an object.  How do I convert the object to an integer?  

I don't really see anything concrete in the discussion groups and it's really frustrating.  

Regards,
Thomas
     
--
This email was Anti Virus scanned.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Zend_Db_Table_Abstract

Alessandro Pellizzari
In reply to this post by Thomas List
Il Tue, 05 Apr 2011 15:17:15 -0400, Thomas List ha scritto:

> Hi,

> I am trying to return the max value of a row in my database.  The code I
> used is as follows:
>
>  public function getMaxLogId()
>      {
>           return $this->fetchAll(
>             $this->select()
>                 ->from($this, array(new Zend_Db_Expr('max(log_id) as
>                 log_id')))
>       );
>        
>      }
>
> which returns an object.  How do I convert the object to an integer?

return $this->fetchOne(
             $this->select()
                 ->from($this, array(new Zend_Db_Expr('max(log_id) as
                 log_id')))->log_id;

Not tested, but should work.

Bye.



--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Loading...