Seite 1 von 1

Suchfunktion nach Vorgaben

Verfasst: 09.02.2021 19:56
von waldkatze
Ich arbeite an einer Suchfunktion nach Vorgaben.
z.B. Eingabe des Suchbegriff Hotel soll alle Einträge im Datenbankfeld name finden, die den Text Hotel enthalten.

Das ist der betreffende Codeabschnitt:

Code: Alles auswählen

$submit = (isset($_POST['submit'])) ? true : false;
if ($submit)
{
    $submit = (isset($_POST['submit'])) ? true : false;
		
    $id	 = request_var('id', 0);
    $name   = (request_var ('name', '', true)) ? " OR name LIKE '%" . $db->sql_escape(request_var ('name', '', true)) . "%'" : '';
    $plz       = (request_var ('plz', '', true)) ? " OR plz LIKE '%" . $db->sql_escape(request_var ('plz', '', true)) . "%'" : '';
    $ort       = (request_var('ort', '', true)) ? " OR ort LIKE '%" . $db->sql_escape(request_var('ort', '', true)) . "%'": '';
			
    $sql = 'SELECT tz.id, tz.name, tz.land, tz.kategorie, tz.region, tz.plz, tz.ort, tz.strasse, tz.telefon, tz.email, tz.homepage, tz.user_id, tz.post_time, tz.wlan,  
	      u.user_id, u.username, u.user_colour, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height,
	      ct.country_id, ct.country_name, ct.country_image
			
	        FROM ' . $this->tourziel_table . ' tz		
	        JOIN ' . USERS_TABLE . ' u
	        ON u.user_id = tz.user_id
		JOIN ' . $this->tourziel_country_table . ' ct
	        ON tz.land = ct.country_id 
			
		WHERE id = ' . (int) $id 
                . $name
                . $plz
                . $ort;
	        $sql .= ' ORDER BY name ASC'; 
		$result = $this->db->sql_query($sql);
		
            while ($row = $this->db->sql_fetchrow($result)) 
            {    				        
                $this->template->assign_block_vars('search', array(			
                    'POST_ID'        => $row['id'],
		    'POST_NAME'      => $row['name'],
		    'POST_PLZ'       => $row['plz'],
                    'POST_ORT'       => $row['ort'],
                    'POST_STRASSE'   => $row['strasse'],
                    'POST_TELEFON'   => $row['telefon'],
                    'POST_EMAIL'     => $row['email'], 
                    'POST_HOMEPAGE'  => $row['homepage'], 
				
		    'POST_LAND'      => $row['land'],
		    'POST_REGION'    => $row['region'],
		    'POST_KATEGORIE' => $row['kategorie'],
		    'POST_WLAN'      => $row['wlan'],

		    'POST_DATE'		 => (!empty($row['post_time'])) ? $this->user->format_date($row['post_time']) : '-',
				
	            'COUNTRY_ID'     => $row['country_id'],
		    'COUNTRY_NAME'   => $row['country_name'],
	               
	            'USER_ID'	     => $row['user_id'], 
	            'POSTER_AUTHOR'  => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
	            'POSTER_AVATAR'  => get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'], $row['user_avatar_height']), 
                ));  						         
            }
            $this->db->sql_freeresult($result);
		
            $this->template->assign_vars(array(
                'U_FORM_ACTION' => $this->u_action,
		    ));  
	    }
		
		return $this->helper->render('tzv_main_search.html', $this->user->lang('MAIN_SEARCH'));
}
Absenden bringt folgende Fehlermeldung:
[phpBB Debug] PHP Notice: in file [ROOT]/ext/waldkatze/tzv/controller/main.php on line 873: Undefined variable: db

Recoverable fatal error: Object of class waldkatze\tzv\controller\main could not be converted to string in /homepages/40/d51130xxxx/htdocs/test_board/ext/waldkatze/tzv/controller/main.php on line 873


Zeile 873 ist das:

Code: Alles auswählen

$name = (request_var ('name', '', true)) ? " OR name LIKE '%" . $db->sql_escape(request_var ('name', '', true)) . "%'" : '';
In meinen alten MOD mit phpBB 3.0.x funktionierte das wunderbar.

Hat jemand eine Idee was ich in der Zeile falsch geschrieben habe ?

Re: Suchfunktion nach Vorgaben

Verfasst: 09.02.2021 20:17
von BNa
$db-> ist an der Stelle nicht deklariert, daher ohne Funktion.
$this->irgendwas ist der 3.1.*/3.2.*/3.3.* Kontext:
https://www.phpbb.com/community/viewtop ... #p14831206

Re: Suchfunktion nach Vorgaben

Verfasst: 09.02.2021 20:35
von waldkatze
@ BNa

Habe die Zeile so geändert:

Code: Alles auswählen

$name      = (request_var ('name', '', true)) ? " OR name LIKE '%" . $this->$db->sql_escape(request_var ('name', '', true)) . "%'" : '';
Bringt diese Fehlermeldung:

Code: Alles auswählen

[phpBB Debug] PHP Notice: in file [ROOT]/ext/waldkatze/tzv/controller/main.php on line 873: Undefined variable: db
[phpBB Debug] PHP Notice: in file [ROOT]/ext/waldkatze/tzv/controller/main.php on line 873: Undefined property: waldkatze/tzv/controller/main::$

Fatal error: Uncaught Error: Call to a member function sql_escape() on null in /homepages/40/d51130xxxx/htdocs/test_board/ext/waldkatze/tzv/controller/main.php:873 Stack trace: #0 /homepages/40/d51130xxxx/htdocs/test_board/vendor/symfony/http-kernel/HttpKernel.php(151): waldkatze\tzv\controller\main->search() #1 /homepages/40/d51130xxxx/htdocs/test_board/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(phpbb\symfony_request), 1) #2 /homepages/40/d51130xxxx/htdocs/test_board/app.php(35): Symfony\Component\HttpKernel\HttpKernel->handle(Object(phpbb\symfony_request)) #3 {main} thrown in /homepages/40/d51130xxxx/htdocs/test_board/ext/waldkatze/tzv/controller/main.php on line 873

Re: Suchfunktion nach Vorgaben

Verfasst: 09.02.2021 20:38
von chris1278
Waldkatze du solltest solche code meldungen entweder als [quoute] oder als [code] bringen und nicht in dem [c] bbcode.

Re: Suchfunktion nach Vorgaben

Verfasst: 09.02.2021 21:16
von Kirk
Bin zwar nur per Smartphone online aber ersetzte das $this->$db durch jenes $this->db

Re: Suchfunktion nach Vorgaben

Verfasst: 10.02.2021 08:07
von waldkatze
Vielen Dank an BNa und Udo.
Jetzt geht das.