I found some similar ones, but not the exact one that I need:
Background information: I am using MySQL with PDO class
Currently, I am using two queries as follows:
To get one page of data:
$sql = "SELECT * FROM `tab`
WHERE `condition` = :condition
LIMIT $page_size OFFSET $offset";
$array = array('condition'=>$condition);
$mysql = $pdo->prepare($sql);
$mysql->execute($array);
To get total amount of rows:
$sql = "SELECT COUNT(*) FROM `tab`
WHERE `condition` = :condition";
$array = array('condition'=>$condition);
$mysql = $pdo->prepare($sql);
$mysql->execute($array);