SQL LIMIT returns "zero" - 0 - rows (IN PHP)
I have an error in this query when the query returns zero rows. <b>
Error Number: 1064
You have an error in the SQL syntax; check the manual that matches your version of MySQL server for the correct syntax to use around '-20.20' on 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:
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 (); } code> I do not want to make another query to count the strings before I make this query. Thanks for answers.The OFFSET value of the LIMIT must be a non-negative integer constant. Quoting MySQL Documentation :
The
LIMITcan be used to limit the number of rows returned by theSELECT.LIMITtakes one or two numeric arguments, which must be non-negative integer constants (unless prepared statements are used).