use Tk; use Tk::HList; use DBI; # Ende der Datenbankinitialisierung $top = new MainWindow; my $f = $top->Frame()->pack(-expand => 1); my $e = $f->Entry(-width => 50,)->pack(side => 'left', -expand => 1, -fill => 'x'); my $such_b = $f->Button(-text => 'Suchen', -default => 'active', -command => \&suchen,)->pack(-side => 'left'); $top->bind ('', sub{$such_b-> invoke()}); MainLoop; sub suchen { my $such = $e->get(); my ($dbh, $sth); $dbh = DBI->connect ("DBI:mysql:host=192.168.42.6;database=cdmcrm", "www-data", "www-data", {PrintError => 0, RaiseError => 1}); $sth = $dbh->prepare (" SELECT Nachname, Vorname, Telefon, Email FROM mitarbeiter WHERE Nachname LIKE '$such%'"); $sth->execute(); $hlist = $top->Scrolled("HList", -header => 1, -columns => 4, -scrollbars => 'osoe', -width => 70, -selectbackground => 'SeaGreen3', )->pack(-expand => 1, -fill => 'both'); $hlist->header('create', 0, -text => 'Nachname'); $hlist->header('create', 1, -text => 'Vorname'); $hlist->header('create', 2, -text => 'Telefon'); $hlist->header('create', 3, -text => 'Email'); my @zeile; my $i=0; while (@zeile = $sth->fetchrow_array()) { $hlist->add($i); $hlist->itemCreate($i, 0, -text => "$zeile[0]"); $hlist->itemCreate($i, 1, -text => "$zeile[1]"); $hlist->itemCreate($i, 2, -text => "$zeile[2]"); $hlist->itemCreate($i, 3, -text => "$zeile[3]"); $i++; } $sth->finish(); $dbh->disconnect() }