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

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

Flink ·

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

Andrea_Herzog ·

Hallo Flink,

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

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:

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

woida ·
$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:

$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/

Andrea_Herzog ·

Hallo woida,

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

Jetzt bekomme ich diese 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

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

Andrea_Herzog ·

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

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

Stoneage ·

Hallo Andrea,

wenn überhaupt muss es so heissen:

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

marksta ·

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

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