Syntax for db count query needed

R

Ruby Quest

can any one tell me the controller syntax for db record count?

I want to specify this mysql query syntax in controller

select count(*) from tablename where user_id=7;

what is the controller syntax similar to the above sql quert?


thanks and regards
Rubyquest
 
K

khaines

can any one tell me the controller syntax for db record count?

I want to specify this mysql query syntax in controller

select count(*) from tablename where user_id=7;

what is the controller syntax similar to the above sql quert?

Sure! I do it like this:

count = ksdbh.count:)Tablename) {|r| r.user_id == 7}

Other people probably do it differently, though. Details are important
when asking a "How do I...?" question.

I imagine that you are actually asking how to do that using ActiveRecord,
right? If so, while you will probably get a correct answer for AR from
someone on this list, the better place to ask those questions is the Rails
list.


Thanks,

Kirk Haines
 
K

khaines

Thanks kirk Haines!

It works...

Thanks again

That works for you? What ORM are you using? That was not AR syntax, but
rather, syntax for the Kansas ORM.


Kirk Haines
 
R

Ruby Quest

NO...i used below method and it works.

@itemCount=Item.count:)all, :joins=>"my table joins goes here",
:conditions =>["my conditions goes here"];


sorry for the confusion....

Thanks
RQ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top