function getPageCount($table) { global $pageSize; return ceil(fetchRowCount($table) / $pageSize); }
function getRecords($con, $where, $orderby, $limit, $offset, $pagesize, &$rowcount) { $sql_where = getWhere($where); $sql_orderby = getOrderBy($orderby, $count); $sql_limit = getLimit($limit, 0); $sql_page = getLimit($pagesize, $offset); if ($limit) { if ($pagesize) { $sql = "SELECT * FROM phones " . $sql_where . $sql_orderby . $sql_limit; $sql = "select * from ( " . $sql . " ) a " . $sql_page; $records = fetchRows($con, $sql); if (!$records) { return false; } $rc_sql = "SELECT 1 FROM phones " . $sql_where . $sql_limit; $rc_sql = "select count(*) AS rowcount from ( " . $rc_sql . " ) rc"; $rowcount = fetchRowCount($con, $rc_sql); if (!$rowcount) { return false; } return $records; } $sql = "SELECT * FROM phones " . $sql_where . $sql_orderby . $sql_limit; $records = fetchRows($con, $sql); $rowcount = count($records); return $records; } if ($pagesize) { $sql = "SELECT * FROM phones " . $sql_where . $sql_orderby . $sql_page; $records = fetchRows($con, $sql); if (!$records) { return false; } $rc_sql = "SELECT 1 FROM phones " . $sql_where; $rc_sql = "select count(*) AS rowcount from ( " . $rc_sql . " ) rc"; $rowcount = fetchRowCount($con, $rc_sql); if (!$rowcount) { return false; } return $records; } $sql = "SELECT * FROM phones " . $sql_where . $sql_orderby; $records = fetchRows($con, $sql); if (!$records) { return false; } $rowcount = count($records); return $records; }