---
title: "Selectbox in Frontend sortieren"
url: "https://www.typo3.net/d/79248-selectbox-in-frontend-sortieren"
source: "typo3.net"
tags: ["Extensions","Entwicklung","Datenbank","Frage","TCA"]
created: "2008-07-07"
last_reply: "2008-07-08"
replies: 5
solved: false
page: 1
pages: 1
lang: "de"
---

# Selectbox in Frontend sortieren

Extensions › Entwicklung · 5 Antworten · gestartet 2008-07-07

## Eröffnungsbeitrag

**wwt** · 2008-07-07 · [Beitrag #1](https://www.typo3.net/d/79248-selectbox-in-frontend-sortieren/1)

Wie bekomme ich es hin, dass ich eine Selectbox auch im FE sortieren kann??

```php
	function enterFEevent() {
	
			// get Categories:
		$this->cat = $this->validRows("tx_mjseventpro_cat", "title", 'cat');
```

gibt mir ja den title aus.

Ich brauch eaber etwas wie:

```php
$res = mysql_query("SELECT 'title' FROM `tx_mjseventpro_cat` ORDER BY `uid` ASC;");
```

Wie kann ich das kombinieren??

Die Einstellungen in der TCA

```php
"cat" => Array (		
			"exclude" => 1,		
			"label" => "LLL:EXT:mjseventpro/locallang_db.php:tx_mjseventpro.cat",		
			"config" => Array (
				"type" => "select",	
				"foreign_table" => "tx_mjseventpro_cat",	
				"foreign_table_where" => "ORDER BY uid",	
				"size" => 1,	
				"minitems" => 0,
				"maxitems" => 1,
				"items" => Array (
					Array("", 0),
				),
			)
		),
```

greifen nur im Backend.

## Antworten

### [#2](https://www.typo3.net/d/79248-selectbox-in-frontend-sortieren/2) · just2b · 2008-07-07

pass die Funktion validRows an

georg

### [#3](https://www.typo3.net/d/79248-selectbox-in-frontend-sortieren/3) · wwt · 2008-07-08

Hallo Georg!
Ja schon, dann kann ich statt title z.b. uid ausgeben lassen. Das geht ja auch problemlos.

Ich brauche aber: Ausgabe "title", sortiert nach "uid".
Diese mysql_query bringe ich aber nicht hin.

Kannst Du mir bitte ein Beispiel geben?

### [#4](https://www.typo3.net/d/79248-selectbox-in-frontend-sortieren/4) · just2b · 2008-07-08

ich kenne die ext nicht, aber wenn du schon dort drin herumcodedest, kannst du ja auch direkt statt der fkt deine eigene aufrufen

georg

### [#5](https://www.typo3.net/d/79248-selectbox-in-frontend-sortieren/5) · wwt · 2008-07-08

...statt der fkt...?

Also für alle hier nochmals ausführlich:

Die ext heisst "MJS_eventpro" und ist für Events mit Frontend-editing. Leider seit Jahren nicht mehr weiterentwickelt worden. Habe sie aber trotzdem soweit sehr gut an meine Bedürfnisse anpassen können.

Im Wesentlichen geht es jetzt noch um die Datei "pi1/class.tx_mjseventpro_pi1.php" welche unter anderem dafür zuständig ist, dass die Kategorien ausgegeben werden. dies findet 3mal statt:

Das 1. Mal ca. Zeile 238 (hier Zeile 3):

```php
// Adds the category selector box:
$markerArray['###CATEGORY_LABEL###'] = $this->pi_getLL("listFieldHeader_cat");
$markerArray['###CATEGORY_SELECT###'] = $this->htmlSelect("tx_mjseventpro_cat", "title", 'cat');
```

Das 2. Mal ca. Zeile 1045:

```php
	/**
	 * Make the selectorbox with categories.
	 * $fNmm is the name of the field in the main table.
	 */
	function htmlSelect($table='', $fieldName='', $fNmm='') {
		$validRowsArray = $this->validRows($table, $fieldName, $fNmm);
		$selectedValue = $this->piVars[$fNmm];
		$opt = array();
		$opt[] = '<option value="'.
				htmlentities($this->pi_linkTP_keepPIvars_url('', $this->allowCaching))
				.'">alle</option>';
			// Show selectorbox only, if there are any categories.
		if($validRowsArray) {
			foreach ($validRowsArray as $uid => $title) {
				$opt[] = '<option value="'.
					htmlentities($this->pi_linkTP_keepPIvars_url(array("cat" => $uid), $this->allowCaching))
					.'"'.
					($selectedValue == $uid ? " SELECTED" : "")
					.'>'.
					htmlentities($title)
					.'</option>';
			}
			return '<select onChange="document.location=this.options[this.selectedIndex].value;">'.implode("", $opt).'</select>';
		}
		return '';
	} // htmlSelect

	/**
	 * Make the selectorbox with categories.
	 * $fNmm is the name of the field in the main table.
	 *
	 * @param string $table
	 * @param string $fieldName
	 * @param string $fNmm
	 * @return string
	 */
	function htmlSelect4input($table='', $fieldName='', $fNmm='') {
// Der Wert der Variablen  $table wird nie benutzt (Zeile 1081)
// Der Wert der Variablen  $fieldName wird nie benutzt (Zeile 1081)
		$validRowsArray = $this->$fNmm;
		$selectedValue = $this->piVars[$fNmm];
		$opt = array();
		$opt[] = '<option value="">-</option>';
			// Show selectorbox only, if there are any categories.
		if($validRowsArray) {
			foreach ($validRowsArray as $uid => $title) {
				$opt[] = '<option value="'.$uid.'"'.($selectedValue == $uid ? " SELECTED" : "").'>'.htmlentities($title).'</option>';
			}
			return '<select name="tx_mjseventpro_pi1['.$fNmm.']">'.implode("", $opt).'</select>';
		}
		return '';
	} // htmlSelect4input
```

Das 3. Mal ca. Zeile 1209, hier findet die Ausgabe der Datenbak im FE-Formular statt:

```php
	function enterFEevent() {

			// get Categories:
		$this->cat = $this->validRows("tx_mjseventpro_cat", "title");
```

Mein Problem:
Überall wird "title" ausgegeben, was ich natürlich nach "uid" ändern kann. Dann habe ich aber nur die "uid" Nummer da stehen.

Ich brauch als Ausgabe den "title", aber sortiert nach "uid".
Und das ist die Entscheidende Frage:
Wie geht das?????
Wer hat einen Ansatz, die Datenbankausgabe zu sortieren?

### [#6](https://www.typo3.net/d/79248-selectbox-in-frontend-sortieren/6) · wwt · 2008-07-08

Habs gelöst:

```php
	function validRows($table, $fieldName) {
	// check this: pi_getCategoryTableContents()    !!!
		 $workaround = $this->piVars['sword'];
		 $this->piVars['sword'] = FALSE;
		//$res = $this->pi_exec_query($table,'','',0,'',$fieldName,'');
		    //Oben das ORIGINAL, Unten die neue Abfrage query 
                    //direkt in die tx_mjseventpro_cat
		$res = $this->pi_exec_query(tx_mjseventpro_cat);
		while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))	{
                        //hier die definition in welcher Tabelle (='uid')
			$validRowsArray[$row['uid']] = $row[$fieldName];
		}
		$this->piVars['sword'] = $workaround;
		return $validRowsArray;
	} // validRows
```

---

Quelle: „Selectbox in Frontend sortieren“, typo3.net, https://www.typo3.net/d/79248-selectbox-in-frontend-sortieren
Beiträge von Mitgliedern des Forums. Bitte mit Link auf die Diskussion zitieren.
