[TYPO3-core] RFC #13467: add getField() function to database API
Stefan Geith
typo3dev2010.nospam1 at geithware.de
Tue Feb 9 19:06:59 CET 2010
Martin Kutschker schrieb:
> [...] but it can be taken a step further if the
> function would retrieve a whole column (ie a list of field values).
I already suggested something like that:
http://bugs.typo3.org/view.php?id=11050
/**
+ * Creates and executes a SELECT SQL-statement AND traverse result set
and returns array with array[uid_field]=select_field
+ *
+ * @param string result array will carry this field names value as index
+ * @param string result array will carry this field names value as value
+ * @param string See exec_SELECTquery()
+ * @param string See exec_SELECTquery()
+ * @param string See exec_SELECTquery()
+ * @param string See exec_SELECTquery()
+ * @param string See exec_SELECTquery()
+ * @return array Array of values: array[uid_field]=select_field.
+ */
+ function
exec_SELECTgetField($uid_field,$value_field,$from_table,$where_clause,$groupBy='',$orderBy='',$limit='')
{
+ $select_fields = $uid_field . (strcmp($uid_field,$value_field) ? ','
. $value_field : '');
+ $res =
$this->exec_SELECTquery($select_fields,$from_table,$where_clause,$groupBy,$orderBy,$limit);
+ $output = FALSE;
+ if (!$this->sql_error()) {
+ $output = array();
+
+ while($tempRow = $this->sql_fetch_assoc($res)) {
+ $output[$tempRow[$uid_field]] = $tempRow[$value_field];
+ }
+ $this->sql_free_result($res);
+ }
+ return $output;
+ }
More information about the TYPO3-team-core
mailing list