From: tjhunt Date: Tue, 15 Aug 2006 13:44:22 +0000 (+0000) Subject: New function get_field_select(). X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=ab757152ec6874f4f9d3b152385a98c4b7cc0406;p=moodle.git New function get_field_select(). --- diff --git a/lib/datalib.php b/lib/datalib.php index baf59a6c7a..6a216d8bb8 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -946,17 +946,22 @@ function get_records_sql_menu($sql) { * @return mixed the specified value, or false if an error occured. */ function get_field($table, $return, $field1, $value1, $field2='', $value2='', $field3='', $value3='') { - - global $CFG; $select = where_clause($field1, $value1, $field2, $value2, $field3, $value3); + return get_field_select($table, $return, $select); +} - $rs = get_recordset_sql('SELECT ' . $return . ' FROM ' . $CFG->prefix . $table . ' ' . $select); - - if ($rs && $rs->RecordCount() == 1) { - return $rs->fields[0]; - } else { - return false; - } +/** + * Get a single value from a table row where a particular select clause is true. + * + * @uses $CFG + * @param string $table the table to query. + * @param string $return the field to return the value of. + * @param string $select A fragment of SQL to be used in a where clause in the SQL call. + * @return mixed the specified value, or false if an error occured. + */ +function get_field_select($table, $return, $select) { + global $CFG; + return get_field_sql('SELECT ' . $return . ' FROM ' . $CFG->prefix . $table . ' ' . $select); } /**