Error Number: 1064 You have a...">

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.
+3
source share
3 answers

You cannot specify a negative value in LIMIT :

 LIMIT -20,20 

This means that you want to return lines 20 , starting with -20 , which is incorrect .

+3
source

The OFFSET value of the LIMIT must be a non-negative integer constant. Quoting MySQL Documentation :

The LIMIT can be used to limit the number of rows returned by the SELECT . LIMIT takes one or two numeric arguments, which must be non-negative integer constants (unless prepared statements are used).

+4
source

The limit cannot be negative.

+2
source

All Articles