Thread Primitives Telefonbuch: Perl TK (18 answers)
Opened by Ronnie at 2003-09-02 15:21

Ronnie
 2003-09-02 16:21
#42275 #42275
User since
2003-08-14
2022 Artikel
BenutzerIn
[default_avatar]
Wie verhindere ich das er jedes mal 'ne neue HList erzeugt? z.Z. sieht mein Skript so aus:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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 ('<Return>', 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()

}


Gruss,
Ronnie

View full thread Primitives Telefonbuch: Perl TK