I have an error in this query, when the query returns zero rows.
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘-20,20’ at line 3
SELECT pl.name,pl.email FROM players pl JOIN players_bonus pl_b on pl.id = pl_b.id_player WHERE pl_b.id_bonus = 3 LIMIT -20,20
My method is:
public function getPViews_num_rows($limit = array(0,20),$page_num = 1,$id) { $limit = "LIMIT {$limit[0]},{$limit[1]}";$sql = "SELECT pl.name,pl.email FROM players pl JOIN players_bonus pl_b on pl.id = pl_b.id_player WHERE pl_b.id_bonus = ? {$limit}"; $where = array($id); $query = $this->db->query ( $sql,$where ); return $query->num_rows (); }
I don't wanna do another query to count rows,before I do this query.
Thanks for the answers.
You can not specify negative value to
LIMITclause:It means you want to return
20rows starting from-20which is wrong.