Pagination with complex query

Hi All!

Can i ask you for a little help?

I have a complex query used with createCommand(), and i don’t know, ho to use CPagination with it.

my code is (from yii-blogdemo-enhanced, google code):

public function findTagWeights($limit=20)


                $sql="SELECT name, COUNT(postId) AS weight

        FROM Tag, PostTag


        GROUP BY name

        HAVING COUNT(postId)>0

        ORDER BY weight DESC

        LIMIT $limit";



                foreach($rows as $row)





                        foreach($rows as $row)




                return $tags;


How can i use this code with pagination instead of using $limit?

I can’t figure this out.