[Typo3-dev] Newbie:Getting value from another table

Franz Holzinger franz at fholzinger.com
Mon Jun 13 11:50:11 CEST 2005


TABLE tx_rgzitate_zitat (
	zitat text NOT NULL,
	autorz int(11) unsigned DEFAULT '0' NOT NULL, => Database
relation zu tx_rgzitate_autor.autor
)
TABLE tx_rgzitate_autor (
	uid int(11) unsigned DEFAULT '0' NOT NULL auto_increment,
	autor tinytext NOT NULL,
)



/**
* Sets the internal sorting fields.
* The field list will be used for SELECT.
*
* @param string Commalist of fields
* @return void
*/
function setSortFields($sortFields='') {
if($sortFields) {
$this->sorting = ' ORDER BY '.$sortFields;
} else {
$this->sorting = ($TCA[$this->table]['ctrl']['sortby'] ? ' ORDER BY 
'.$TCA[$this->table]['ctrl']['sortby'] : ' 
'.$TCA[$this->table]['ctrl']['default_sortby']);
}

if ($mm_prependTableName) {
$sortFields=array();
$sortingArr = explode(',',$this->sorting);
foreach ($sortingArr as $sort) {
$sortFields[] = $this->table.'.'.sort;
}
$this->sorting = implode (',', $sortFields);
}
}


/**
* Sets the internal where clause for enable-fields..
* The field list will be used as enable-fields.
*
*
* @param string Commalist of fields. "FE" set the proper frontend 
fields, "BE" for backend.
* @return void
* @see enableFields()
*/
function setEnableFields ($fields) {
if ($fields=='FE') {
$this->where_default = 
$this->enableFields('delete,disabled,starttime,endtime,fe_group');
} elseif ($fields=='BE') {
$this->where_default = $this->enableFields('delete');
} else {
$this->where_default = $this->enableFields($fields);
}
}


/**
* Gets records with uid IN $uids
* You can set $field to a list of fields (default is '*')
* Additional WHERE clauses can be added by $where (fx. ' AND blabla=1')
*
* @param string Commalist of UIDs of records
* @param boolean Enable sorting
* @param string Commalist of fields to select
* @param string Additional WHERE clause, eg. " AND blablabla=0"
* @return array Returns the rows if found, otherwise empty array
*/
function getRecords ($uids, $sorting=true, $fields='', $where='') {
global $TYPO3_DB;
$fields = $fields?$fields:$this->fieldList;
$sort = $sorting?$this->sorting:'';
$tables = $this->tables;

// in this example this has been explicitly defined here -- needs deletion
// tx_rgzitate_zitat muß auch eine uid haben!
$fields = 'tx_rgzitate_zitat.zitat zitat, tx_rgzitate_autor.autor autor';
$tables = 'tx_rgzitate_zitat, tx_rgzitate_autor';

// SELECT tx_rgzitate_zitat.zitat zitat, tx_rgzitate_autor.autor autor 
FROM tx_rgzitate_zitat, tx_rgzitate_autor WHERE tx_rgzitate_zitat.autorz 
= tx_rgzitate_autor.uid
$rows = array();

$res = $TYPO3_DB->exec_SELECTquery($fields, $tables, 
'tx_rgzitate_zitat.autorz = tx_rgzitate_autor.uid');

while ($row = $TYPO3_DB->sql_fetch_assoc($res)) {
$rows[$row['uid']]=$row;
}

error_log ('************** TEST++ Ende' . $rows , 0);
}


Still some improvements have to be done.


Franz




More information about the TYPO3-dev mailing list