From 0eeac484f3bf59e568b842e2cb8197c2df893c89 Mon Sep 17 00:00:00 2001 From: moodler Date: Thu, 31 Jul 2003 12:18:22 +0000 Subject: [PATCH] Extended get_records so it can deal with LIMITs now --- lib/datalib.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/datalib.php b/lib/datalib.php index cd7917dc6b..41a770a0dd 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -358,11 +358,12 @@ function get_record_select($table, $select="", $fields="*") { } -function get_records($table, $field="", $value="", $sort="", $fields="*") { +function get_records($table, $field="", $value="", $sort="", $fields="*", $limitfrom="", $limitnum="") { /// Get a number of records as an array of objects /// Can optionally be sorted eg "time ASC" or "time DESC" /// If "fields" is specified, only those fields are returned /// The "key" is the first column returned, eg usually "id" +/// limitfrom and limitnum must both be specified or not at all global $CFG; @@ -372,11 +373,26 @@ function get_records($table, $field="", $value="", $sort="", $fields="*") { $select = ""; } + if ($limitfrom) { + switch ($CFG->dbtype) { + case "mysql": + $limit = "LIMIT $limitfrom,$limitnum"; + break; + case "postgres7": + $limit = "LIMIT $limitnum OFFSET $limitfrom"; + break; + default: + $limit = "LIMIT $limitnum,$limitfrom"; + } + } else { + $limit = ""; + } + if ($sort) { $sort = "ORDER BY $sort"; } - return get_records_sql("SELECT $fields FROM $CFG->prefix$table $select $sort"); + return get_records_sql("SELECT $fields FROM $CFG->prefix$table $select $sort $limit"); } function get_records_select($table, $select="", $sort="", $fields="*") { -- 2.39.5