Skip to content

Commit

Permalink
Updated get_records_select() to help Eloy out. :-)
Browse files Browse the repository at this point in the history
  • Loading branch information
moodler committed Feb 13, 2004
1 parent f064a3d commit 4f91b29
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/datalib.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,22 +482,38 @@ 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;

if ($select) {
$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");
}


Expand Down

0 comments on commit 4f91b29

Please sign in to comment.