Zum Inhalt springen

Extension für DB Abfrage - SQL - Query

Erstellt am 23. September 2005 · 31 Antworten · letzte Antwort am 29. September 2005 · Seite 1 von 2

Tags: PHP, Datenbank, Frage

Andrea_Herzog ·

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".

<?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']);
}

?>
woida ·
$query = "SELECT * FROM  user_bivmetal_bivmetal WHERE plz LIKE '42657'ORDER BY sorting"

hier fehlt ein Leerzeichen vor "ORDER":

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

Die Zeile muß Du wieder einfügen:

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

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

Andrea_Herzog ·

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

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

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

Andrea_Herzog ·

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

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

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

woida ·

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

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

und schau obs dann geht.

Stoneage ·

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

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

<?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']);
}

?>
Andrea_Herzog ·

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?

Andrea_Herzog ·

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.

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

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 ....

<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

woida ·

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.

Andrea_Herzog ·

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.

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

Stoneage ·

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

 <?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.

Andrea_Herzog ·

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:

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.

<!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

Stoneage ·

@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
  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']);
  }

?>
Andrea_Herzog ·

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

Andrea_Herzog ·

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.

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:

<?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

woida ·

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)