---
title: "Extension für DB Abfrage - SQL - Query"
url: "https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query"
source: "typo3.net"
tags: ["Extensions","Entwicklung","Datenbank","Frage","PHP"]
created: "2005-09-23"
last_reply: "2005-09-29"
replies: 31
solved: false
page: 1
pages: 1
lang: "de"
---

# Extension für DB Abfrage - SQL - Query

Extensions › Entwicklung · 31 Antworten · gestartet 2005-09-23

## Eröffnungsbeitrag

**Andrea_Herzog** · 2005-09-23 · [Beitrag #1](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/1)

Hallo zusammen,
ich möchte gerne eine - bereits lauffähige Datenbank(abfrage) ins Typo3 einpfelgen. Hatte ich mir so einfach vorgestellt
Ich habe also mit dem Wizzard ein Plugin erstellt, dass auch im BE angezeigt wird und dort auch mit Daten befüllt werden kann.
Erstellt ist eine Tabelle mit drei Spalten für Name, PLZ, Ort.

Das Formular hat ein Suchfeld, in welches die PLZ eingegeben werden soll. Nach Klick auf Submit werden die Adressen im gesuchten PLZ ausgegeben.

Eigentlich ganz einfach - außer man ist der Laie schlechthin, was die Extensionprogrammierung angeht.

Ich denke ich brauche für dieses kleine Ding auch kein seperates Template.

Kann mir jemand sagen, wo und wie ich eine Query in das Ding einbaue und die Ausgabe unter das Formular liste?

Vielen Dank im Voraus,
Andrea

```html
<?php
/***************************************************************
*  Copyright notice
*
*  (c) 2005 Andrea ()
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
 * Plugin 'plugin.beispiel' for the 'user_beispiel' extension.
 *
 * @author	Andrea <>
 */


require_once(PATH_tslib.'class.tslib_pibase.php');

class user_bivmetal_pi1 extends tslib_pibase {
	var $prefixId = 'user_beispiel_pi1';		// Same as class name
	var $scriptRelPath = 'pi1/class.user_beispiel_pi1.php';	// Path to this script relative to the extension dir.
	var $extKey = 'user_beispiel';	// The extension key.
	var $pi_checkCHash = TRUE;
	
	/**
	 * [Put your description here]
	 */
	function main($content,$conf)	{
		$this->conf=$conf;
		$this->pi_setPiVarDefaults();
		$this->pi_loadLL();
		
	
		$content='
    
			<strong>Sie suchen einen xxx in Ihrer Nähe?</strong><BR>
			<p>Tragen Sie einfach die gewünschte Postleitzahl, oder auch nur die erste Zahl oder die 
	    ersten beiden Zahlen ein und betätigen den Submit - Button. Schon erhalten Sie die gewünschte Information.</p>
			<h3>This is a form:</h3>
			<form action="'.$this->pi_getPageLink($GLOBALS['TSFE']->id).'" method="POST">
				<input type="hidden" name="no_cache" value="1">
				<input type="text" name="'.$this->prefixId.'[plz]" value="'.htmlspecialchars($this->piVars['$_POST["plz"]']).'">
				<input type="submit" name="'.$this->prefixId.'[submit_button]" value="'.htmlspecialchars($this->pi_getLL('submit_button_label')).'">
			</form>
      
		<BR>
			<p>You can click here to '.$this->pi_linkToPage('get to this page again',$GLOBALS['TSFE']->id).'</p>
		';
	
		return $this->pi_wrapInBaseClass($content);
	}
}



if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/user_beispiel/pi1/class.user_beispiel_pi1.php'])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/user_beispiel/pi1/class.user_beispiel_pi1.php']);
}

?>
```

:o  :o  :o  :o  :o

## Antworten

### [#2](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/2) · Flink · 2005-09-24

Hallo

> **Andrea_Herzog schrieb:**
>
> Kann mir jemand sagen, wo und wie ich eine Query in das Ding einbaue und die Ausgabe unter das Formular liste?

Na eben danach.  :o

```php
<?php
...
			<form action="'.$this-">pi_getPageLink($GLOBALS['TSFE']->id).'" method="POST">
				<input type="hidden" name="no_cache" value="1" />
				<input type="text" name="'.$this-" />prefixId.'[plz]" value="'.htmlspecialchars($this->piVars['$_POST["plz"]']).'">
				<input type="submit" name="'.$this-" />prefixId.'[submit_button]" value="'.htmlspecialchars($this->pi_getLL('submit_button_label')).'">
			</form>
      
		<br />
			<p>You can click here to '.$this->pi_linkToPage('get to this page again',$GLOBALS['TSFE']->id).'</p>
		';
	// jetzt die ausgelesenen Daten
        $content2 = '<h3>Ergebnis</h3>';
        $content2 .= '<table>';
        $plz = intval (t3lib_div::_GP($this->prefixId.'[plz]'));
        
	$where = 'plz="'.$plz.'"';
        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tx_bivmetal_address', $where .' AND pid IN ('.$this->pid_list.')'.$this->cObj->enableFields('tx_bivmetal_address'));
	
        while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
            $content2 .= '<tr><td>'.$row['name'].'</td></tr><tr><td>'.$row['plz'].'</td></tr><tr><td>'.$row['ort'].'</td></tr>';
        }
        $content2 .= '</table>';
        $content = $content . $content2;
	return $this->pi_wrapInBaseClass($content);
	}
}
...
?>
```

[/quote]

### [#3](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/3) · Andrea_Herzog · 2005-09-26

Hallo Flink,

danke für die Infos.
Aber es geht leider immer noch nicht. Ich bekomme folgende Fehlermeldung:

```html
Parse error: parse error in /typo3_src-3.8.0/typo3/ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php on line 68

Warning: Cannot modify header information - headers already sent by (output started at /typo3_src-3.8.0/typo3/ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php:68-) in /typo3_src-3.8.0/typo3/sysext/cms/tslib/class.tslib_fe.php on line 2612
```

Der Code sieht jetzt so aus:

```html
<?php
/***************************************************************
*  Copyright notice
*
*  (c) 2005 Andrea (a.herzog@kienastdv.de)
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
 * Plugin 'plugin.bivmetal' for the 'user_bivmetal' extension.
 *
 * @author	Andrea <a.herzog@kienastdv.de>
 */


require_once(PATH_tslib.'class.tslib_pibase.php');

class user_bivmetal_pi1 extends tslib_pibase {
	var $prefixId = 'user_bivmetal_pi1';		// Same as class name
	var $scriptRelPath = 'pi1/class.user_bivmetal_pi1.php';	// Path to this script relative to the extension dir.
	var $extKey = 'user_bivmetal';	// The extension key.
	var $pi_checkCHash = TRUE;
	
	/**
	 * [Put your description here]
	 */
	function main($content,$conf)	{
		$this->conf=$conf;
		$this->pi_setPiVarDefaults();
		$this->pi_loadLL();
		
	
		$content='
			<strong>Sie suchen einen Metallbildner-Betrieb in Ihrer Nähe?</strong><br />
			<p>Hier können Sie ein Unternehmen in Ihrer Nähe finden.</p>
			<p>Tragen Sie einfach die gewünschte Postleitzahl, oder auch nur die erste Zahlen oder die </p>
	                                <p>ersten beiden Zahlen ein und betätigen den Submit - Button. Schon erhalten Sie die gewünschte Information.</p>
			<h3>This is a form:</h3>
			<form action="'.$this-">pi_getPageLink($GLOBALS['TSFE']->id).'" method="POST">
				<input type="hidden" name="no_cache" value="1" />
				<input type="text" name="'.$this-" />prefixId.'[plz]" value="'.htmlspecialchars($this->piVars['$_POST["plz"]']).'">
				<input type="submit" name="'.$this-" />prefixId.'[submit_button]" value="'.htmlspecialchars($this->pi_getLL('submit_button_label')).'">
			</form>
			<br />
			<p>You can click here to '.$this->pi_linkToPage('get to this page again',$GLOBALS['TSFE']->id).'</p>
		';
    //Die ausgelesenen Daten
    $content = '<h3>Ergebnis:</h3>';
    $content2 .= '<table>';
    $plz = intval (t3lib_div::_GP($this->prefixId.'[plz]'));
    
    $where = 'plz="'.$plz.'"';
    $res = $GLOBALS['usr_p11417_1']->exec_SELECTquery('*', 'tx_bivmetal_adress', $where .' AND pid IN ('$this->pid_list.')'.$this->cObj->enableFields('tx_bivmetal_adress'));
           while ($row = $GLOBALS['usr_p11417_1']->sql_fetch_assoc($res)) {
           $content2 .='<tr><td>'.$row['name'].'</td></tr><tr><td>'. $row['plz'].'</td></tr><tr><td>' . $row ['ort'].'</td></tr>';
           }
           $content2 .= '</table>';
           $content = $content . $content2;
           return $this->pi_wrapInBaseClass($content);
           } 
	

}



if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php'])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php']);
}

?>
```

Wo habe ich etwas falsch gemacht?

Gruß
Andrea

PS: Gibt es zu dem ganzen Extension und Datenbankabfragezeug ein brauchbares Tutorial?

### [#4](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/4) · woida · 2005-09-26

```php
$res = $GLOBALS['usr_p11417_1']->exec_SELECTquery('*', 'tx_bivmetal_adress', $where .' AND pid IN ('$this->pid_list.')'.$this->cObj->enableFields('tx_bivmetal_adress'));
```

wenn der Code vom Forum nicht verunstaltet wurde, dann fehlt nach dem "AND pid IN ('" ein Punkt:

```php
$res = $GLOBALS['usr_p11417_1']->exec_SELECTquery('*', 'tx_bivmetal_adress', $where .' AND pid IN ('.$this->pid_list.')'.$this->cObj->enableFields('tx_bivmetal_adress'));
```

Doku zu den MySQL-Wrapper Funktionen:
<http://typo3.org/documentation/document-library/doc_core_cgl/The_wrapper_class/>

Für Extension allgemein:
<http://typo3.org/documentation/document-library/player_profile_basic/>

### [#5](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/5) · Andrea_Herzog · 2005-09-26

Hallo woida,

danke, der Punkt hat gefehlt. Aber geht immer noch nicht.

Jetzt bekomme ich diese Fehlermeldung:

```html
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /typo3_src-3.8.0/t3lib/class.t3lib_db.php on line 741

Warning: Cannot modify header information - headers already sent by (output started at /typo3_src-3.8.0/t3lib/class.t3lib_db.php:741) in /typo3_src-3.8.0/typo3/sysext/cms/tslib/class.tslib_fe.php on line 2612
```

Trotzdem Danke,
Andrea

### [#6](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/6) · Andrea_Herzog · 2005-09-26

Hallo zusammen,
ich komme einfach nicht weiter.
Hier noch einmal der Code,
vielleicht kann jemand das Geheimnis lüften.

```html
<?php
/***************************************************************
*  Copyright notice
*
*  (c) 2005 Andrea (a.herzog@kienastdv.de)
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
 * Plugin 'plugin.bivmetal' for the 'user_bivmetal' extension.
 *
 * @author	Andrea <a.herzog@kienastdv.de>
 */


require_once(PATH_tslib.'class.tslib_pibase.php');

class user_bivmetal_pi1 extends tslib_pibase {
	var $prefixId = 'user_bivmetal_pi1';		// Same as class name
	var $scriptRelPath = 'pi1/class.user_bivmetal_pi1.php';	// Path to this script relative to the extension dir.
	var $extKey = 'user_bivmetal';	// The extension key.
	var $pi_checkCHash = TRUE;
	
	/**
	 * [Put your description here]
	 */
	function main($content,$conf)	{
		$this->conf=$conf;
		$this->pi_setPiVarDefaults();
		$this->pi_loadLL();
		
	
		$content='
			<strong>Sie suchen einen Metallbildner-Betrieb in Ihrer Nähe?</strong><BR>
			<p>Hier können Sie ein Unternehmen in Ihrer Nähe finden.</p>
			<p>Tragen Sie einfach die gewünschte Postleitzahl, oder auch nur die erste Zahlen oder die </p>
	                                <p>ersten beiden Zahlen ein und betätigen den Submit - Button. Schon erhalten Sie die gewünschte Information.</p>
			<h3>This is a form:</h3>
			<form action="'.$this->pi_getPageLink($GLOBALS['TSFE']->id).'" method="POST">
				<input type="hidden" name="no_cache" value="1">
				<input type="text" name="'.$this->prefixId.'[plz]" value="'.htmlspecialchars($this->piVars['$_POST["plz"]']).'">
				<input type="submit" name="'.$this->prefixId.'[submit_button]" value="'.htmlspecialchars($this->pi_getLL('submit_button_label')).'">
			</form>
			<BR>
			<p>You can click here to '.$this->pi_linkToPage('get to this page again',$GLOBALS['TSFE']->id).'</p>
		';
    //Die ausgelesenen Daten
    $content = '<h3>Ergebnis:</h3>';
    $content2 .= '<table>';
    $plz = intval (t3lib_div::_GP($this->prefixId.'[plz]'));
    
    $where = 'plz="'.$plz.'"';
    $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'user_bivmetal_bivmetal', $where .' AND pid IN ('.$this->pid_list.')'.$this->cObj->enableFields('user_bivmetal_bivmetal'));
           while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
           $content2 .='<tr><td>'.$row['firma_1'].'</td></tr><tr><td>'. $row['plz'].'</td></tr><tr><td>' . $row ['ort'].'</td></tr>';
           }
           $content2 .= '</table>';
           $content = $content . $content2;
           return $this->pi_wrapInBaseClass($content);
           } 
	

}



if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php'])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php']);
}

?>
```

Gibt es eigentlich nur diese Tutorials von Hachmeister und Hofmann und sonst nichts zum Thema Extensions?

Gruß
Andrea

### [#7](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/7) · Stoneage · 2005-09-26

Hallo Andrea,

wenn überhaupt muss es so heissen:

```typoscript
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'user_bivmetal_bivmetal', 'pid IN ('.$this->pid_list.')');
```

Der $where-Parameter wird als 3. Argument der Funktion übergeben, und nicht als separate Anweisung! Deine SQL-Abfrage ist total vermurkst. Das besagt auch die MySQL-Fehlermeldung:

> Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /typo3_src-3.8.0/t3lib/class.t3lib_db.php on line 741

Du musst Dir unbedingt die Doku-Tipps von woida durchlesen, da steht eigentlich alles drin.

Gruß,

T.

### [#8](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/8) · marksta · 2005-09-26

Hallo Andrea

Kleiner Tipp: Am Anfang der Extension (innerhalb vom main) folgende Zeile einfügen:

$GLOBALS['TYPO3_DB']->debugOutput = true;

Dies ist sehr hilfreich.

Gruss
Markus

### [#9](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/9) · Andrea_Herzog · 2005-09-26

Hallo Markus,
vielen Dank. Habe ich eingebaut.

Leider klappt das Ding immer noch nicht.
Ich komme trotz der Tutorials einfach nicht weiter. Ich glaube ich habe alles nur "verschlimmbessert".

```html
<?php
/***************************************************************
*  Copyright notice
*
*  (c) 2005 Andrea (a.herzog@kienastdv.de)
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
 * Plugin 'plugin.bivmetal' for the 'user_bivmetal' extension.
 *
 * @author	Andrea <a.herzog@kienastdv.de>
 */


require_once(PATH_tslib.'class.tslib_pibase.php');

class user_bivmetal_pi1 extends tslib_pibase {
	var $prefixId = 'user_bivmetal_pi1';		// Same as class name
	var $scriptRelPath = 'pi1/class.user_bivmetal_pi1.php';	// Path to this script relative to the extension dir.
	var $extKey = 'user_bivmetal';	// The extension key.
	//var $pi_checkCHash = TRUE;
  var $conf;
	
	/**
	 * [Put your description here]
	 */
	function main($content,$conf)	{
		$this->conf=$conf;
    $GLOBALS['TYPO3_DB']->debugOutput = true;

    //$this->pi_setPiVarDefaults();
		//$this->pi_loadLL();
		$content='
			<strong>Sie suchen einen Metallbildner-Betrieb in Ihrer Nähe?</strong><BR>
			<p>Hier können Sie ein Unternehmen in Ihrer Nähe finden.</p>
			<p>Tragen Sie einfach die gewünschte Postleitzahl, oder auch nur die erste Zahlen oder die </p>
	                                <p>ersten beiden Zahlen ein und betätigen den Submit - Button. Schon erhalten Sie die gewünschte Information.</p>
			<h3>This is a form:</h3>
			<form action="'.$this->pi_getPageLink($GLOBALS['TSFE']->id).'" method="POST">
				<input type="hidden" name="no_cache" value="1">
				<input type="text" name="'.$this->prefixId.'[plz]" value="'.htmlspecialchars($this->piVars['$_POST["plz"]']).'">
				<input type="submit" name="'.$this->prefixId.'[submit_button]" value="'.htmlspecialchars($this->pi_getLL('submit_button_label')).'">
			</form>
			<BR>
			<p>You can click here to '.$this->pi_linkToPage('get to this page again',$GLOBALS['TSFE']->id).'</p>
		';
    //$rows=$this->getItems();
    while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
          
   
    //Die ausgelesenen Daten
    $content = '<h3>Ergebnis:</h3>';
    $content2 .= '<table>';
    $content2 .='<tr><td>'.$row['firma_1'].'</td></tr><tr><td>'. $row['plz'].'</td></tr><tr><td>' . $row ['ort'].'</td></tr>';
    $content2 .= '</table>';
    $plz = intval (t3lib_div::_GP($this->prefixId.'[plz]'));
    $content = $content . $content2;
           return $this->pi_wrapInBaseClass($content);
           } 
    function getItems()	{
                
                	// pid_list is the pid/list of pids from where to fetch the guest items.
		$config["pid_list"] = trim($this->cObj->stdWrap($this->conf["pid_list"],$this->conf["pid_list."]));
		$config["pid_list"] = $config["pid_list"] ? implode(t3lib_div::intExplode(",",$config["pid_list"]),",") : $GLOBALS["TSFE"]->id;
		list($pid) = explode(",",$config["pid_list"]);

		$query = "SELECT * FROM  user_bivmetal_bivmetal WHERE plz LIKE '42657'ORDER BY sorting";
		$res = mysql(TYPO3_db,$query);
		$out=array();
		while($row = mysql_fetch_assoc($res))	{
			$out[]=$row;
		}
		return $out;
    
      
           
           
           
	

}


if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php'])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php']);
}

?>
```

### [#10](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/10) · woida · 2005-09-26

```php
$query = "SELECT * FROM  user_bivmetal_bivmetal WHERE plz LIKE '42657'ORDER BY sorting"
```

hier fehlt ein Leerzeichen vor "ORDER":

```php
$query = "SELECT * FROM  user_bivmetal_bivmetal WHERE plz LIKE '42657' ORDER BY sorting"
```

### [#11](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/11) · Andrea_Herzog · 2005-09-26

Hallo Woida,

herzlichen Dank,
das war es aber auch nicht.

#angry#
Andrea

### [#12](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/12) · Stoneage · 2005-09-26

Die Zeile muß Du wieder einfügen:

```typoscript
 //$rows=$this->getItems();
```

Sonst wird Deine Funktion getItems() mit der DB-Abfrage sonst nie aufgerufen.

### [#13](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/13) · woida · 2005-09-26

Du solltest vielleicht mal die Fehlermelung und die Datenbankstruktur posten.

### [#14](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/14) · Andrea_Herzog · 2005-09-26

Hallo,
danke für deine Unterstützung.
Hier ist die Fehlermeldung

```html
Parse error: parse error in /typo3_src-3.8.0/typo3/ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php on line 104

Warning: Cannot modify header information - headers already sent by (output started at /typo3_src-3.8.0/typo3/ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php:104) in /typo3_src-3.8.0/typo3/sysext/cms/tslib/class.tslib_fe.php on line 2612
```

Hier ist nochmal der Code:
<?php
/***************************************************************
*  Copyright notice
*
*  (c) 2005 Andrea (a.herzog@kienastdv.de)
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  <http://www.gnu.org/copyleft/gpl.html>.
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
 * Plugin 'plugin.bivmetal' for the 'user_bivmetal' extension.
 *
 * @author	Andrea <a.herzog@kienastdv.de>
 */

require_once(PATH_tslib.'class.tslib_pibase.php');

class user_bivmetal_pi1 extends tslib_pibase {
	var $prefixId = 'user_bivmetal_pi1';		// Same as class name
	var $scriptRelPath = 'pi1/class.user_bivmetal_pi1.php';	// Path to this script relative to the extension dir.
	var $extKey = 'user_bivmetal';	// The extension key.
	//var $pi_checkCHash = TRUE;
  var $conf;

	/**
	 * [Put your description here]
	 */
	function main($content,$conf)	{
		$this->conf=$conf;
    $GLOBALS['TYPO3_DB']->debugOutput = true;

//$this->pi_setPiVarDefaults();
		//$this->pi_loadLL();
		$content='
			<strong>Sie suchen einen Metallbildner-Betrieb in Ihrer Nähe?</strong><BR>
			<p>Hier können Sie ein Unternehmen in Ihrer Nähe finden.</p>
			<p>Tragen Sie einfach die gewünschte Postleitzahl, oder auch nur die erste Zahlen oder die </p>
	                                <p>ersten beiden Zahlen ein und betätigen den Submit - Button. Schon erhalten Sie die gewünschte Information.</p>
			<h3>This is a form:</h3>
			<form action="'.$this->pi_getPageLink($GLOBALS['TSFE']->id).'" method="POST">
				<input type="hidden" name="no_cache" value="1">
				<input type="text" name="'.$this->prefixId.'[plz]" value="'.htmlspecialchars($this->piVars['$_POST["plz"]']).'">
				<input type="submit" name="'.$this->prefixId.'[submit_button]" value="'.htmlspecialchars($this->pi_getLL('submit_button_label')).'">
			</form>
			<BR>
			<p>You can click here to '.$this->pi_linkToPage('get to this page again',$GLOBALS['TSFE']->id).'</p>
		';
    $rows=$this->getItems();
    while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {

    //Die ausgelesenen Daten
    $content = '<h3>Ergebnis:</h3>';
    $content2 .= '<table>';
    $content2 .='<tr><td>'.$row['firma_1'].'</td></tr><tr><td>'. $row['plz'].'</td></tr><tr><td>' . $row ['ort'].'</td></tr>';
    $content2 .= '</table>';
    $plz = intval (t3lib_div::_GP($this->prefixId.'[plz]'));
    $content = $content . $content2;
           return $this->pi_wrapInBaseClass($content);
           }
    function getItems()	{

                	// pid_list is the pid/list of pids from where to fetch the guest items.
		$config["pid_list"] = trim($this->cObj->stdWrap($this->conf["pid_list"],$this->conf["pid_list."]));
		$config["pid_list"] = $config["pid_list"] ? implode(t3lib_div::intExplode(",",$config["pid_list"]),",") : $GLOBALS["TSFE"]->id;
		list($pid) = explode(",",$config["pid_list"]);

$query = "SELECT * FROM  user_bivmetal_bivmetal WHERE plz LIKE '42657' ORDER BY sorting";
		$res = mysql(TYPO3_db,$query);
		$out=array();
		while($row = mysql_fetch_assoc($res))	{
			$out[]=$row;
		}
		return $out;

}

if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php'])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php']);
}

?>

Hier die Tabellenstrukur

```html
Tabelle: user_bivmetal_bivmetal  
  Struktur   Anzeigen   SQL   Suche   Einfügen   Exportieren   Operationen   Leeren   Löschen    
 


       Feld  Typ Attribute Null Standard Extra Aktion 
   uid  int(11)   Nein    auto_increment              
   pid  int(11)   Nein  0                
   tstamp  int(11)   Nein  0                
   crdate  int(11)   Nein  0                
   cruser_id  int(11)   Nein  0                
   deleted  tinyint(4)   Nein  0                
   hidden  tinyint(4)   Nein  0                
   starttime  int(11)   Nein  0                
   endtime  int(11)   Nein  0                
   firma_1  tinytext   Nein                  
   plz  tinytext   Nein                  
   ort  tinytext   Nein                  
 Alle auswählen  /  Auswahl entfernen     markierte:
```

Ich versteh es einfach nicht.

Ich bin für die Hilfe unendlich dankbar.

Viele Grüße

Andrea

### [#15](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/15) · Andrea_Herzog · 2005-09-26

Hallo,
danke für deine Unterstützung.
Hier ist die Fehlermeldung

```html
Parse error: parse error in /typo3_src-3.8.0/typo3/ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php on line 104

Warning: Cannot modify header information - headers already sent by (output started at /typo3_src-3.8.0/typo3/ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php:104) in /typo3_src-3.8.0/typo3/sysext/cms/tslib/class.tslib_fe.php on line 2612
```

Hier ist nochmal der Code:

```html
<?php
/***************************************************************
*  Copyright notice
*
*  (c) 2005 Andrea (a.herzog@kienastdv.de)
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
 * Plugin 'plugin.bivmetal' for the 'user_bivmetal' extension.
 *
 * @author	Andrea <a.herzog@kienastdv.de>
 */


require_once(PATH_tslib.'class.tslib_pibase.php');

class user_bivmetal_pi1 extends tslib_pibase {
	var $prefixId = 'user_bivmetal_pi1';		// Same as class name
	var $scriptRelPath = 'pi1/class.user_bivmetal_pi1.php';	// Path to this script relative to the extension dir.
	var $extKey = 'user_bivmetal';	// The extension key.
	//var $pi_checkCHash = TRUE;
  var $conf;
	
	/**
	 * [Put your description here]
	 */
	function main($content,$conf)	{
		$this->conf=$conf;
    $GLOBALS['TYPO3_DB']->debugOutput = true;

    //$this->pi_setPiVarDefaults();
		//$this->pi_loadLL();
		$content='
			<strong>Sie suchen einen Metallbildner-Betrieb in Ihrer Nähe?</strong><BR>
			<p>Hier können Sie ein Unternehmen in Ihrer Nähe finden.</p>
			<p>Tragen Sie einfach die gewünschte Postleitzahl, oder auch nur die erste Zahlen oder die </p>
	                                <p>ersten beiden Zahlen ein und betätigen den Submit - Button. Schon erhalten Sie die gewünschte Information.</p>
			<h3>This is a form:</h3>
			<form action="'.$this->pi_getPageLink($GLOBALS['TSFE']->id).'" method="POST">
				<input type="hidden" name="no_cache" value="1">
				<input type="text" name="'.$this->prefixId.'[plz]" value="'.htmlspecialchars($this->piVars['$_POST["plz"]']).'">
				<input type="submit" name="'.$this->prefixId.'[submit_button]" value="'.htmlspecialchars($this->pi_getLL('submit_button_label')).'">
			</form>
			<BR>
			<p>You can click here to '.$this->pi_linkToPage('get to this page again',$GLOBALS['TSFE']->id).'</p>
		';
    $rows=$this->getItems();
    while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
          
   
    //Die ausgelesenen Daten
    $content = '<h3>Ergebnis:</h3>';
    $content2 .= '<table>';
    $content2 .='<tr><td>'.$row['firma_1'].'</td></tr><tr><td>'. $row['plz'].'</td></tr><tr><td>' . $row ['ort'].'</td></tr>';
    $content2 .= '</table>';
    $plz = intval (t3lib_div::_GP($this->prefixId.'[plz]'));
    $content = $content . $content2;
           return $this->pi_wrapInBaseClass($content);
           } 
    function getItems()	{
                
                	// pid_list is the pid/list of pids from where to fetch the guest items.
		$config["pid_list"] = trim($this->cObj->stdWrap($this->conf["pid_list"],$this->conf["pid_list."]));
		$config["pid_list"] = $config["pid_list"] ? implode(t3lib_div::intExplode(",",$config["pid_list"]),",") : $GLOBALS["TSFE"]->id;
		list($pid) = explode(",",$config["pid_list"]);

		$query = "SELECT * FROM  user_bivmetal_bivmetal WHERE plz LIKE '42657' ORDER BY sorting";
		$res = mysql(TYPO3_db,$query);
		$out=array();
		while($row = mysql_fetch_assoc($res))	{
			$out[]=$row;
		}
		return $out;
    
      
           
           
           
	

}


if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php'])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php']);
}

?>
```

Hier die Tabellenstrukur

```html
Tabelle: user_bivmetal_bivmetal  
  Struktur   Anzeigen   SQL   Suche   Einfügen   Exportieren   Operationen   Leeren   Löschen    
 


       Feld  Typ Attribute Null Standard Extra Aktion 
   uid  int(11)   Nein    auto_increment              
   pid  int(11)   Nein  0                
   tstamp  int(11)   Nein  0                
   crdate  int(11)   Nein  0                
   cruser_id  int(11)   Nein  0                
   deleted  tinyint(4)   Nein  0                
   hidden  tinyint(4)   Nein  0                
   starttime  int(11)   Nein  0                
   endtime  int(11)   Nein  0                
   firma_1  tinytext   Nein                  
   plz  tinytext   Nein                  
   ort  tinytext   Nein                  
 Alle auswählen  /  Auswahl entfernen     markierte:
```

Ich versteh es einfach nicht.

Ich bin für die Hilfe unendlich dankbar.

Viele Grüße

Andrea #angry#  :o

### [#16](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/16) · woida · 2005-09-26

Ich seh in deiner Tabelle keine Spalte "sorting".
Ändere mal deine Abfrage in

```php
$query = "SELECT * FROM user_bivmetal_bivmetal WHERE plz LIKE '42657'";
```

und schau obs dann geht.

### [#17](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/17) · Stoneage · 2005-09-26

@woida: stimmt.
@Andrea: der ganze code ist total vermurkst.

hier mal ne (hoffentlich halbwegs funktionsfähige korrektur, das formular habe ich rausgenommen).

```php
<?php

require_once(PATH_tslib.'class.tslib_pibase.php');

class user_bivmetal_pi1 extends tslib_pibase {
	var $prefixId = 'user_bivmetal_pi1'; // Same as class name
	var $scriptRelPath = 'pi1/class.user_bivmetal_pi1.php'; // Path to this script relative to the extension dir.
	var $extKey = 'user_bivmetal'; // The extension key.
	//var $pi_checkCHash = TRUE;
	var $conf;

	function main($content,$conf) {
		$this->conf=$conf;
		$GLOBALS['TYPO3_DB']->debugOutput = true;
				
		$content = '<h3>Ergebnis:</h3>';
		$content2 = '<table>';
		
		//Die ausgelesenen Daten	
		$rows=$this->getItems();
		foreach ($rows as $value) {				
			$content2 .='<tr><td>'.$rows['firma_1'].'</td></tr><tr><td>'. $rows['plz'].'</td></tr><tr><td>' . $rows['ort'].'</td></tr>';
		}
		
		$content2 .= '</table>';
		$content = $content . $content2;
		return $this->pi_wrapInBaseClass($content);	
	}

	function getItems() {
		
		$query = "SELECT * FROM user_bivmetal_bivmetal WHERE plz LIKE '42657'";
		$res = mysql(TYPO3_db,$query);
		$out=array();
		while($row = mysql_fetch_assoc($res)) {
			$out[]=$row;
		}
		return $out;
	}

}

if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php']) {
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php']);
}

?>
```

### [#18](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/18) · Andrea_Herzog · 2005-09-26

Hallo Woida,
danke für die Hilfe. Aber leider war es das auch nicht. Fehlermeldung bleibt die gleiche.
Die PLZ ist ja auch nur ein Dummy-Wert, schließlich soll in dem Feld plz gesucht werden, wenn der Benutzer einge Eingabe einer PLZ in das Formularfeld schreibt.

Habe ich nur gemacht, weil ich das mal überhaupt testen wollte.

Aber is nich.

Was nun? Woran kann es denn noch liegen?

### [#19](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/19) · Stoneage · 2005-09-26

@Andrea: ähm, probier mal meinen code aus! der funktioniert bestimmt!

### [#20](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/20) · Andrea_Herzog · 2005-09-26

hallo Tetramatrix,

ich bin schon so im Wahn, dass ich deine "kleine" Post gar nicht gesehen habe.

Also: geht nicht wirklich. Hier ist die Fehlermeldung.
Allerdings wird das Wort "Ergebnis" schon einmal ausgegeben.

```html
Warning: Cannot modify header information - headers already sent by (output started at /typo3_src-3.8.0/typo3/ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php:75) in /typo3_src-3.8.0/typo3/sysext/cms/tslib/class.tslib_fe.php on line 2612
```

Allerdings habe ich es ohne Formular getestet,den Formularteil kriege ich nicht hin. Ich weiss nicht, an welche Position und auch nicht wie ich auf das Feld PLZ zugreife. Der Wert

```html
value="'.htmlspecialchars($this->piVars['$_POST["plz"]']).'"
```

muss ja irgendwie in die Abfrage rein.
Ich habe das ganze Ding ja auch schon als "normales PHP-Mey-Sql-Ding am rennen. Aber die Extensions sind für mich noch ein Buch mit ....

```html
<form action="'.$this-">pi_getPageLink($GLOBALS['TSFE']->id).'" method="POST">
			                	  <input type="hidden" name="no_cache" value="1" />
				                  <input type="text" name="'.$this-" />prefixId.'[plz]" value="'.htmlspecialchars($this->piVars['$_POST["plz"]']).'">
				                  <input type="submit" name="'.$this-" />prefixId.'[submit_button]" value="'.htmlspecialchars($this->pi_getLL('submit_button_label')).'">
			                  </form><br />
```

Danke für die Hilfe,

Andrea

### [#21](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/21) · woida · 2005-09-26

Hallo Andrea,
nimm doch mal nur den Code von Tertamatrix und schau obs dann geht.
In der Fehlermeldung die du gepostet hast, steht was von Zeile 75, so lange ist aber sein Code gar nicht.
Wenn das geht, kannst du das ganze erweitern (Formular). Aber zuerst wäre eine funktionierende Basis nicht schlecht.

### [#22](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/22) · Andrea_Herzog · 2005-09-26

Hallo Woida,
habe ich ja gemacht, ohne Formular. Ich habe nur in der Zeile 17 bei $content2 .= '<table>'; den Punkt ergänzt, dort stand nur $content2 = '<table>'.

Hier ist die Fehlermeldung, wenn ich Tetramatrix´Code verwende.

```html
Warning: Cannot modify header information - headers already sent by (output started at /typo3_src-3.8.0/typo3/ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php:75) in /typo3_src-3.8.0/typo3/sysext/cms/tslib/class.tslib_fe.php on line 2612
```

Verzweifel!!

Gruß
Andrea

### [#23](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/23) · Stoneage · 2005-09-26

@Andrea: Zeile 17 war in Ordnung. Bitte so lassen. Zeile 22 war aber fehlerhaft. hier nochmal eine Korrektur:

```php
 <?php
  require_once(PATH_tslib.'class.tslib_pibase.php');

  class user_bivmetal_pi1 extends tslib_pibase {
		  var $prefixId = 'user_bivmetal_pi1'; // Same as class name
		  var $scriptRelPath = 'pi1/class.user_bivmetal_pi1.php'; // Path to this script relative to the extension dir.
		  var $extKey = 'user_bivmetal'; // The extension key.
		  //var $pi_checkCHash = TRUE;
		  var $conf;   

		  function main($content,$conf) {
				  $this->conf=$conf;
				  $GLOBALS['TYPO3_DB']->debugOutput = true;							 

				  $content = '<h3>Ergebnis:</h3>';
				  $content2 = '<table>';
				  
				  //Die ausgelesenen Daten
				  $rows=$this->getItems();
				  foreach ($rows as $value) {
						  $content2 .='<tr><td>'.$value['firma_1'].'</td></tr><tr><td>'. $value['plz'].'</td></tr><tr><td>' . $value['ort'].'</td></tr>';
				  }				 

				  $content2 .= '</table>';
				  $content = $content . $content2;
				  return $this->pi_wrapInBaseClass($content);     
		  }

   

		  function getItems() {
				  $query = "SELECT * FROM user_bivmetal_bivmetal WHERE plz LIKE '42657'";
				  $res = mysql(TYPO3_db,$query);
				  $out=array();
				  while($row = mysql_fetch_assoc($res)) {
						  $out[]=$row;
				  }  
				  return $out;
		  }       

  }

   

  if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php']) {  
		  include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php']);
  }

?>
```

Eventl. noch den typo3conf cache löschen.

### [#24](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/24) · Andrea_Herzog · 2005-09-26

Hi Tetramatrix,

jetzt geht es - fast. Vielen Dank. Es wird ein Datensatz mit der entsprechenden PLZ ausgegeben. Was bin ich dir dankbar. #giggle#

Allerdings habe ich immer noch diese doofe Fehlermeldung:

```html
Warning: Cannot modify header information - headers already sent by (output started at /typo3_src-3.8.0/typo3/ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php:79) in /typo3_src-3.8.0/typo3/sysext/cms/tslib/class.tslib_fe.php on line 2612
```

Was immer das bedeutet, ist jedenfalls nichts gutes. Wie kann ich das beheben? #angry#

Auch wenn ich jetzt unverschämt werde:

Kannst du mir sagen, wie ich ein Formular erstelle, dass genau ein Feld hat, in das der Interessent die gewünschte PLZ eingibt, Submit klickt und dann erst die gewünschten Adressen ausgegeben werden?

Ich schicke dir mal den Code des PHP-Dokuments, dass ich für diese Abfrage erstellt habe, allerdings nicht für Typo.

```html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
  <head>
    <title>New Document</title>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  </head>
  <body>
 
<h1>Adressen der Metallbildner - Abfrage</h1>
Suchformular mit nur einem Feld zur Eingabe der gewünschten PLZ
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<!-- Feldinhalt, also Eingabe des Besuchers soll im Feld gespeichert werden value= -->
Suche nach PLZ: <input type="text" name="plz" value = "<?php echo $_POST["plz"];?>">
<input type="submit" name="suchen" value="submit" /><br />


</form>

<?PHP 
//Variable nicht leer
if (!empty ($_POST["plz"]))  
{

  $iVerbNr = mysql_pconnect( "localhost", "root", "") 
  or 
  die( "<h2>Verbindungsfehler</h2>" . mysql_error() );  
     
  @mysql_select_db("bivmetall", $iVerbNr) 
  or 
  die( "<h2>Datenbank existiert nicht: </h2>" . mysql_error() ); 
     
  $tabellenname = "metallbildner"; 
  $postleit = $_POST["plz"];
  
  //$plz=array("00000","10000","20000","30000", "40000", "50000","60000", "70000","80000","90000");
     
// Postleitzahl wird abgefragt  
// Abfrage nach der PLZ, wenn nur 4 eigegeben wird, werden alle, die mit 4 beginnen, ausgegeben. 
// Wird 41 eingegeben, dann alle die mit 41 anfangen. Dafür steht LIKE 'Variable%'   

    
    
    $SQLAbfrage = "SELECT * FROM $tabellenname WHERE plz LIKE '$postleit%' ";
    
    $Ergebnis = mysql_query($SQLAbfrage, $iVerbNr) 
    or 
    die( "<h2>Abfragefehler</h2>" . mysql_error() );  
    
    $nAnzZeilen = mysql_num_rows($Ergebnis);
    
        if ((!empty ($_POST["plz"])) && ($nAnzZeilen > 0)) {
        
        // String gibt über die Variablen die Anzahl der gefundenen Datensätze aus.  
        echo "<h3>Im gewünschten Postleitbereich " . $postleit ." wurden " . $nAnzZeilen . " Adressen gefunden!</h3>"; 
          
        echo "<h2>Adressen im gewünschten PLZ-Bereich</h2>";  
        echo "<table border="1">"; 
        echo "<tr>"; 
        echo "<th>Firma</th>"; 
        echo "<th>Firma 2</th>";
        echo "<th>Straße</th>"; 
        echo "<th>Nr.</th>";
        echo "<th>PLZ</th>";
        echo "<th>Ort</th>"; 
        echo "<th>Telefon</th>";
        echo "<th>DW</th>";
        echo "<th>Telefax</th>";
        echo "<th>DW</th>";
        echo "<th>Email</th>";
        echo "<th>Internet</th>";
        echo "</tr>"; 
        
        while ( $aDaten = mysql_fetch_array( $Ergebnis ) ) 
        { 
              
              echo "<tr>"; 
              echo "<td>" . $aDaten["firma_1"] . "</td>"; 
              echo "<td>" . $aDaten["firma_2"] . "</td>";
              echo "<td>" . $aDaten["strasse"] . "</td>";
              echo "<td>" . $aDaten["hausnr"] . "</td>"; 
              echo "<td>" . $aDaten["plz"] . "</td>"; 
              echo "<td>" . $aDaten["ort"] . "</td>";
              echo "<td>" . $aDaten["tel"] . "</td>";
              echo "<td>" . $aDaten["tel_dw"] . "</td>";
              echo "<td>" . $aDaten["fax"] . "</td>";
              echo "<td>" . $aDaten["fax_dw"] . "</td>";
              echo "<td>" . $aDaten["email"] . "</td>";
              echo "<td>" . $aDaten["internet"] . "</td>";
              
           echo "</tr>"; 
        } 
        
        echo "</table>"; 
        // Klammer zu der 1. If-Abfrage, ob die Variable $_POST ["plz"]gesetzt ist 
        }
    
        else  
        {
        echo "Nichts gefunden";
        }

}

?> 
 </body>
</html>
```

Wie übersetzt man dieses Formular für die Typo3 - Datei?

Für jede Hilfe dankbar,

Andrea

### [#25](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/25) · Stoneage · 2005-09-26

@Andrea: Der Fehler kommt wahrscheinlich vom Debug-Output. Den hab ich jetzt mal rausgenommen. Anbei der Code für Dein Formular. Ich habe mir die Ausgabe der vielen Felder erspart, da hatte ich dann doch keine Lust mehr. Kleine Kurzeinführung: Eine Extension besteht zunächst aus einer Klasse und der main() Funktion. Diese Klasse erbt massig viele Funktionen von der Klasse tslib_pibase. Das ist so von T3 vorgegeben und man muß sich daran halten. Die main() Funktion wird von T3 automatisch aufgerufen, wenn es Deine Extension in einer Seite findet, also ist die schon mal sehr wichtig. Dein "Php-Skript" könnte man auch ganz in die main() integrieren, aber der Übersichtshalber habe ich 3 Funktionen draus gemacht. Außerdem hast Du die SQL-Abrage nicht T3 konform programmiert, sondern einfach nur  SQL-Befehle genommen. Das geht auch, ist aber kein guter Stil. In der Klasse tslib_pibase befinden sich einige interessante Funktionen um mysql-db anzusprechen. Hier findest Du die offizielle Referenz: <http://typo3.org/fileadmin/typo3api-3.8.0/> (einfach nach tslib_pibase suchen).

```php
 <?php
  require_once(PATH_tslib.'class.tslib_pibase.php');

  class user_bivmetal_pi1 extends tslib_pibase {
		  var $prefixId = 'user_bivmetal_pi1'; // Same as class name
		  var $scriptRelPath = 'pi1/class.user_bivmetal_pi1.php'; // Path to this script relative to the extension dir.
		  var $extKey = 'user_bivmetal'; // The extension key.
		  //var $pi_checkCHash = TRUE;
		  var $conf;   

		  function main($content,$conf) {
				$this->conf=$conf;
				$this->pi_setPiVarDefaults();
				$this->pi_loadLL();
				$this->pi_USER_INT_obj=1;	# Configuring so caching is not expected. This value means that no cHash params are ever set. We do this, because it's a USER_INT object!

				$content='
						<strong>Sie suchen einen Metallbildner-Betrieb in Ihrer Nähe?</strong><br />
						<p>Hier können Sie ein Unternehmen in Ihrer Nähe finden.</p>
						<p>Tragen Sie einfach die gewünschte Postleitzahl, oder auch nur die erste Zahlen oder die </p>
						<p>ersten beiden Zahlen ein und betätigen den Submit - Button. Schon erhalten Sie die gewünschte Information.</p>
						<h3>This is a form:</h3>
						<form action="'.$this-">pi_getPageLink($GLOBALS['TSFE']->id).'" method="POST">
						<input type="hidden" name="no_cache" value="1" />
						<input type="text" name="'.$this-" />prefixId.'[plz]" value="'.htmlspecialchars($this->piVars['$_POST["plz"]']).'">
						<input type="submit" name="'.$this-" />prefixId.'[submit_button]" value="'.htmlspecialchars($this->pi_getLL('submit_button_label')).'">
						</form>
						<br />
						<p>You can click here to '.$this->pi_linkToPage('get to this page again',$GLOBALS['TSFE']->id).'</p>
						';						
						
				if (!empty($this->piVars['plz'])) {
					
					$content .= $this->lookupPlz($content, $this->piVars['plz'])); 
					return $this->pi_wrapInBaseClass($content);
					
				} else {
				
					return $this->pi_wrapInBaseClass($content);
				}

			}			

			function lookupPlz($content,$plz) {
				  
				  //Die ausgelesenen Daten
				  $rows = $this->getItems($plz);
				  
				  if (count($rows) == 0)  {				  
						$content .= "Nichts gefunden";				  
				  } else {					
						$content. = '<h3>Ergebnis:</h3>';
						$content2 = '<table>';				  
						foreach ($rows as $value) {
							  $content2 .='<tr><td>'.$value['firma_1'].'</td></tr><tr><td>'. $value['plz'].'</td></tr><tr><td>' . $value['ort'].'</td></tr>';
						}
						$content2 .= '</table>';
						$content = $content . $content2;
				  }				  
				  
				  return $content;    
		  }

   

		  function getItems($plz) {
				  $query = "SELECT * FROM user_bivmetal_bivmetal WHERE plz LIKE '".$plz."'";
				  $res = mysql(TYPO3_db,$query);
				  $out=array();
				  while($row = mysql_fetch_assoc($res)) {
						  $out[]=$row;
				  }  
				  return $out;
		  }       

  }

   

  if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php']) {  
		  include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php']);
  }

?>
```

### [#26](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/26) · Andrea_Herzog · 2005-09-26

Hallo T.,
vielen, vielen Dank. Werde ich morgen früh sofort testen (jetzt erst pubertären Zwerg zum Schlafen überreden).

Ich danke dir sehr und gebe sofort Bescheid. Bis morgen und gute Nacht,

Andrea

### [#27](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/27) · Andrea_Herzog · 2005-09-27

Hallo T.,

:p Es klappt!!!!

Sei dir meiner unendlichen Dankbarkeit gewiss!!
Allerdings musste ich den Code an manchen Stellen ändern. Im Anschluss der lauffähige Code.

Allerdings ist die Fehlermeldung immer noch da.

```html
Warning: Cannot modify header information - headers already sent by (output started at /typo3_src-3.8.0/typo3/ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php:115) in /typo3_src-3.8.0/typo3/sysext/cms/tslib/class.tslib_fe.php on line 2612
```

Der lauffähige Code:

```html
<?php
/***************************************************************
*  Copyright notice
*
*  (c) 2005 Andrea (a.herzog@kienastdv.de)
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
 * Plugin 'plugin.beispiel' for the 'user_beispiel' extension.
 *
 * @author	Andrea <a.herzog@kienastdv.de>
 */
  require_once(PATH_tslib.'class.tslib_pibase.php');
 
  class user_beispiel_pi1 extends tslib_pibase {
                  var $prefixId = 'user_beispiel_pi1'; // Same as class name
                  var $scriptRelPath = 'pi1/class.user_beispiel_pi1.php'; // Path to this script relative to the extension dir.
                  var $extKey = 'user_beispiel'; // The extension key.
                  //var $pi_checkCHash = TRUE;
                  var $conf;   
 
                  function main($content,$conf) {
                                $this->conf=$conf;
                                $this->pi_setPiVarDefaults();
                                $this->pi_loadLL();
                                $this->pi_USER_INT_obj=1;       # Configuring so caching is not expected. This value means that no cHash params are ever set. We do this, because it's a USER_INT object!
 
                                $content='
                                                
                                                <p>Hier können Sie ein Unternehmen in Ihrer Nähe finden.<br />
                                                Tragen Sie einfach die gewünschte Postleitzahl, oder auch nur die erste Zahl oder die 
                                                ersten beiden Zahlen ein und betätigen den Submit - Button. Schon erhalten Sie die gewünschte Information.</p>
                                                <h3>Bitte geben Sie die Postleitzahl ein:</h3>
                                                <form action="'.$this->pi_getPageLink($GLOBALS['TSFE']->id).'" method="POST">
                                                <input type="hidden" name="no_cache" value="1" />
                                                <input type="text" name="'.$this->prefixId.'[plz]" value="'.htmlspecialchars($this->piVars['plz']).'">
                                                <input type="submit" name="'.$this->prefixId.'[submit_button]" value="'.htmlspecialchars($this->pi_getLL('submit_button_label')).'">
                                                </form>
                                                
                                                <p>Klicken Sie hier '.$this->pi_linkToPage('um diese Seite noch einmal aufzurufen',$GLOBALS['TSFE']->id).'</p>
                                                ';                                    
                                                
                                if (!empty($this->piVars['plz'])) {
                                        
                                        $content .= $this->lookupPlz($content, $this->piVars['plz']); 
                                        return $this->pi_wrapInBaseClass($content);
                                        
                                } else {
                                
                                        return $this->pi_wrapInBaseClass($content);
                                }

                        }                     

                        function lookupPlz($content,$plz) {
                                  
                                  //Die ausgelesenen Daten
                                  $rows = $this->getItems($plz);
                                  
                                  if (count($rows) == 0)  {                      
                                                $content = "<h3>Keine Einträge gefunden</h3>";          
                                  } 
                                  else {                              
                                                $content = '<h3>Es wurden ' . $counter . ' Adressen gefunden:</h3>';
                                                $content2 = '<table>';          
                                                foreach ($rows as $value) {
                                                          $content2 .='<tr><td>'.$value['firma_1'].'</td></tr><tr><td>'. $value['plz'].'</td></tr><tr><td>' . $value['ort'].'</td></tr>';
                                                }
                                                $content2 .= '</table>';
                                                $content = $content . $content2;
                                  }                      
                                  
                                  return $content;    
                  }

   

                  function getItems($plz) {
                                  $query = "SELECT * FROM tabellenname WHERE plz LIKE '".$plz."%'";
                                  $res = mysql(TYPO3_db,$query);
                                  
                                  $out=array();
                                  $counter = mysql_num_rows($res);
                                  while($row = mysql_fetch_assoc($res)) {
                                                  $out[]=$row;
                                  }  
                                  return $out;
                  }       

  }

   

  if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/user_beispiel/pi1/class.user_beispiel_pi1.php']) {  
                  include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/user_beispiel/pi1/class.user_beispiel_pi1.php']);
  }

?>
```

Als Tüpfelchen auf dem I wollte ich noch die Anzahl der gefundenen Datensätze ausgeben, mit mysql_num_rows()
Allerdings wird das vollständig ignoriert.
In Zeile 99 habe ich die Variable $counter definiert und in Zeile 80 den Ausgabeteil. Ausgegeben wird allerdings nur "Es wurden Adressen gefunden", nicht "Es wurden 5 Adressen gefunden".
Was habe ich (schon wieder) falsch gemacht? :o

Viele Grüße und 1000 Dank,

Andrea

### [#28](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/28) · woida · 2005-09-27

Die Variable count ist nur innerhalb der Funktion getItems gültig. Die Funktion lookupPlz kennt dann diese Variable nicht mehr. Deshalb wird auch nichts ausgegeben.
Entweder du definierst dir die Variable count bei deinen anderen Klassenvariablen, oder du verwendest sizeof($count)

### [#29](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/29) · Andrea_Herzog · 2005-09-27

Hallo Woida,

danke für den Tipp.

Ich habe die Funktion lookup um

$counter = sizeof($rows);

erweitert. Funktioniert Tadellos.

Vielen Dank,
Andrea

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Hat denn niemand eine Idee zu der Fehlermeldung, die ich
gepostet habe? "Cannot modify....
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

### [#30](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/30) · Andrea_Herzog · 2005-09-28

Hallo zusammen,

ich finde einfach den Fehler nicht.

Der Code, den ich als lauffähigen Code gepostet habe, funktioniert tadellos.
Allerdings habe ich immer noch das große Problem mit der Fehlermeldung

```html
Warning: Cannot modify header information - headers already sent by (output started at /typo3_src-3.8.0/typo3/ext/user_bivmetal/pi1/class.user_bivmetal_pi1.php:117) in /typo3_src-3.8.0/typo3/sysext/cms/tslib/class.tslib_fe.php on line 2612
```

Ich finde einfach nicht heraus, was das sein könnte.

Hat denn niemand eine Idee? #angry#  #angry#

Gruß
Andrea

### [#31](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/31) · Andrea_Herzog · 2005-09-29

Hallo zusammen,

es ist vollbracht11 #giggle#
Für alle, die das geliche Problem haben:
Das Problem war, dass ein Leerzeichen nach dem Ende PHP in der Datei rumschwamm. Das hat mich ein paar Tage und eine Menge graue Haare gekostet.
Aber Mittwald konnte helfen:

> Wie bei allen anderen HTTP-Headern, darf auch vor dem Setzen von Cookies (Sessionfunktionen von PHP4 benutzen standardmäßig Cookies) kein einziges Byte des Codes an den Client gesendet werden. Erst wenn alle HTTP-Header gesendet worden sind, dürfen entsprechende Daten (z. B. HTML) gesendet werden. Typische Stolperfallen sind Leerzeichen bzw. -zeilen vor dem ersten <? bzw. <?php Delimiter des Scripts oder mit include() oder require() importierte Scriptfragmente, die natürlich gar keine Ausgabe produzieren dürfen - weder vor dem ersten Delimiter, noch dazwischen, noch nach dem letzten.Vereinfacht gesagt heißt das das in der tslib (typo3_src-3.8.0/typo3/sysext/cms/tslib/class.tslib_fe.php on line 2612) irgendwelche Headerinformation schon gesendet wurden.

Viele Grüße,

eine glückliche Andrea :p

### [#32](https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query/32) · Andrea_Herzog · 2005-09-29

Ach ja - noch eins dazu:

Immer wenn man die Datei in einem Editor bearbeitet und dann mit Copy und Paste wieder einfügt, schön nach dem Leerzeichen am Ende suchen. Das schleicht sich gerne wieder ein.

Gruß Andrea

---

Quelle: „Extension für DB Abfrage - SQL - Query“, typo3.net, https://www.typo3.net/d/30675-extension-fuer-db-abfrage-sql-query
Beiträge von Mitgliedern des Forums. Bitte mit Link auf die Diskussion zitieren.
