确定分页期间不需要的页面

I am trying to implement pagination.The query,shown below,is used to get the the required no of rows to display per page and also filter some data . The problem is that since i am filtering data in the same query,I am unable to determine the no of pages for the pagination part .

What is the best way to go filter the data as well as know the no of pages required.

$query =   "SELECT c.id AS c_id, v_id, first_name, middle_name, last_name, email
                    FROM  `c` ,  `v`
                    WHERE closed =  'n'
                    AND c.v_id = v.id AND (" . $like_string . ")
                    ORDER BY c.id
                    LIMIT $open_startlimit , $data_perPage";

Create another query which gets all the rows, and use the row count from that.

$query =   "SELECT c.id FROM c, v WHERE closed = 'n' AND c.v_id = v.id AND (" . $like_string . ")";