php - Call row 10 to 20 in decended order -
i'm using pdo. need call data row 10 20 after it's sorted using desc? how can this?
$sql = "select item, price, availability items category = :category order item desc"; $stmt= $connect->prepare($sql); $stmt->execute(array(':category'=>"fruits")); $rslt = $stmt->fetchall(pdo::fetch_assoc); foreach ($rslt $val){ $data[] = $val; }
so guess post answer because comments guess arose confusion , there typo (quote , link had no error).
mysql has function called limit
, https://dev.mysql.com/doc/refman/5.0/en/select.html.
per documentation
the limit clause can used constrain number of rows returned select statement. limit takes 1 or 2 numeric arguments, must both nonnegative integer constants (except when using prepared statements). 2 arguments, first argument specifies offset of first row return, , second specifies maximum number of rows return.
so return rows 10 through 20 can add
limit 9,11
to end of query.
per code:
$sql = "select item, price, availability items category = :category order item desc limit 9, 11"; $stmt= $connect->prepare($sql); $stmt->execute(array(':category'=>"fruits")); $rslt = $stmt->fetchall(pdo::fetch_assoc); foreach ($rslt $val){ $data[] = $val; }
note 11
after 9
because want start @ row 10 , return 11 rows (e.g. 10-20).
Comments
Post a Comment