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


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-27-2008, 07:25 PM
Junior Member
 
Join Date: Mar 2008
Posts: 4
Default Newbie question on count

Hi all,

first of all. I know some PHP, but I am new to Zend Framework. My colleague set up the site, and already made some logic. He' s gone, and I need to get into the site now.

What I would to do is show the number of customers I have in my DB.

What would be the best/easiest way to do this? I am kind of lost in my first hours/days on the framework.

All help really appreciated.

Michel
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-02-2008, 11:17 AM
Junior Member
 
Join Date: Jun 2007
Location: Barcelona
Posts: 8
Default

Assuming $db is the connection to your database and "customers" is your table:

$query = $db->select()->from('customers', array('count'=>'COUNT(*)');
$howMany = $db->fetchOne($query); // $howMany is what you're looking for
__________________
------------------
Loris Candylaftis
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-02-2008, 08:42 PM
Junior Member
 
Join Date: Mar 2008
Posts: 4
Default

Thx for helping me. I need to put this in the Model, right? Like this?

PHP Code:
public function NumberOfCustomers()
    {
        
$query $db->select()->from('customers', array('count'=>'COUNT(*)');
        
$howMany $db->fetchOne($query);
        return 
$howMany;
    } 
I get an error for this, saying an unexpected ';' is there. Every line needs a ;, I think.

Any ideas?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-13-2008, 07:05 PM
lcf's Avatar
lcf lcf is offline
Junior Member
 
Join Date: Apr 2008
Posts: 2
Default

Quote:
Originally Posted by Michel View Post
Thx for helping me. I need to put this in the Model, right? Like this?

PHP Code:
public function NumberOfCustomers()
    {
        
$query $db->select()->from('customers', array('count'=>'COUNT(*)');
        
$howMany $db->fetchOne($query);
        return 
$howMany;
    } 
I get an error for this, saying an unexpected ';' is there. Every line needs a ;, I think.

Any ideas?
I don't know, really...
ahaha))
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-13-2008, 07:15 PM
Junior Member
 
Join Date: Mar 2008
Posts: 4
Default

That helps...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-13-2008, 08:00 PM
lcf's Avatar
lcf lcf is offline
Junior Member
 
Join Date: Apr 2008
Posts: 2
Default

Quote:
Originally Posted by Michel View Post
That helps...
You've missed one bracket. Try to use eyes next time. Sorry for that
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-13-2008, 09:33 PM
Junior Member
 
Join Date: Mar 2008
Posts: 4
Default

Oeps, thx.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-14-2008, 02:51 PM
Elemental's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 119
Default

Yes, any business logic for your data should be in the appropriate model class. Preferably there will be no sql in your controller save the occational where statement to be passed to a defined model method.
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 08:01 PM.