Syntax for db count query needed


#1

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


#2

On Thu, 28 Dec 2006, Ruby Q. wrote:

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 H.


#3

Thanks kirk Haines!

It works...

Thanks again
Rubyquest


#4

On Fri, 29 Dec 2006, Ruby Q. wrote:

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 H.


#5

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

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

Kirk H.