php - Wrong result with FOUND_ROWS() in mySQL -
i have total of 6 rows. when query (say select * table) , have
- limit 3 => found_rows() gives 3 => 3 rows retrieved
- limit 1, 3 => found_rows() gives 4 => 3 rows retrieved
- limit 2, 3 => found_rows() gives 5 => 3 rows retrieved
- limit 3, 3 => found_rows() gives 6 => 3 rows retrieved
- limit 4, 3 => found_rows() gives 6 => 2 rows retrieved
any idea cause of weird behavior?
sql query
select `places`.*, `category`.*, count(places_reviews.place_id) num_reviews, (places_popularity.rating_1 + 2*places_popularity.rating_2 + 3*places_popularity.rating_3 + 4*places_popularity.rating_4 + 5*places_popularity.rating_5)/(places_popularity.rating_1 + places_popularity.rating_2 + places_popularity.rating_3 + places_popularity.rating_4 + places_popularity.rating_5) average_rating, found_rows() num_rows (`places`) join `category` on `places`.`category_id` = `category`.`category_id` left join `places_reviews` on `places_reviews`.`place_id` = `places`.`id` left join `places_popularity` on `places_popularity`.`place_id` = `places`.`id` `places`.`category_id` = 1 , `places`.`name` '%%' group `places`.`id` order `id` desc limit 3
or in block:
select `places`.*, `category`.*, count(places_reviews.place_id) num_reviews, (places_popularity.rating_1 + 2*places_popularity.rating_2 + 3*places_popularity.rating_3 + 4*places_popularity.rating_4 + 5*places_popularity.rating_5)/(places_popularity.rating_1 + places_popularity.rating_2 + places_popularity.rating_3 + places_popularity.rating_4 + places_popularity.rating_5) average_rating, found_rows() num_rows (`places`) join `category` on `places`.`category_id` = `category`.`category_id` left join `places_reviews` on `places_reviews`.`place_id` = `places`.`id` left join `places_popularity` on `places_popularity`.`place_id` = `places`.`id` `places`.`category_id` = 1 , `places`.`name` '%%' group `places`.`id` order `id` desc limit 3
edit :
this looking : http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_found-rows
so in query :
select sql_calc_found_rows .....
Comments
Post a Comment