当前位置: 动力学知识库 > 问答 > 编程问答 >

PHP YII framework searching by count

问题描述:

I have two table called, product and productComment

Product Table Model

productID userID productName

ProductComment Table Model

userID productID Comment

I have two virtual field called comment1 and comment2

when a user fills this field comment1 as 2, and comment2 as 5 for example.

I want to show count of product comment that match from 2 to 5. How can i do that?

Thanks for assistance.

网友答案:

You need to add group and having to your query criteria. You didn't show your relation definition, so depending on your column/relation names you need something along the lines of

$criteria->group = 't.productID';
$criteria->having = 'COUNT(comment.commentID) > '.((int)$this->comment1).
    ' AND COUNT(comment.commentID) < '.((int)$this->comment2);
分享给朋友:
您可能感兴趣的文章:
随机阅读: