From 4f91b2965ea3d550fbc3bb5ccb929057c3720327 Mon Sep 17 00:00:00 2001 From: moodler Date: Fri, 13 Feb 2004 16:32:02 +0000 Subject: [PATCH] Updated get_records_select() to help Eloy out. :-) --- lib/datalib.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/datalib.php b/lib/datalib.php index 6de076dfb5..6248ee52e5 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -482,10 +482,11 @@ function get_records($table, $field="", $value="", $sort="", $fields="*", $limit * Can optionally be sorted eg "time ASC" or "time DESC" * "select" is a fragment of SQL to define the selection criteria * The "key" is the first column returned, eg usually "id" +* limitfrom and limitnum must both be specified or not at all * * @param type description */ -function get_records_select($table, $select="", $sort="", $fields="*") { +function get_records_select($table, $select="", $sort="", $fields="*", $limitfrom="", $limitnum="") { global $CFG; @@ -493,11 +494,26 @@ function get_records_select($table, $select="", $sort="", $fields="*") { $select = "WHERE $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"); } -- 2.39.5