Leser: 2
|< 1 2 >| | 19 Einträge, 2 Seiten |
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
use Tk;
use Tk::HList;
use DBI;
my ($dbh, $sth);
$dbh = DBI->connect ("DBI:mysql:host=192.168.0.6;database=cdmcrm",
"ich", "geheim", {PrintError => 0, RaiseError => 1});
$sth = $dbh->prepare ("SELECT Nachname, Vorname, Telefon, Email FROM mitarbeiter WHERE Nachname LIKE 'H%'");
$sth->execute();
# Ende der Datenbankinitialisierung
$top = new MainWindow;
$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');
&dbget();
MainLoop;
sub dbget {
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()
}
my $such_entry = $top->Entry()->pack();
my $such_eingabe = $such_entry->get;
QuoteOder möchtest Du auf Datenbankebene suchen? Also nur Datensätze mit bestimmten Kriterien in der HList anzeigen? Wie man dann auf SQL-Ebene sucht, ist Dir ja wahrscheinlich klar.
1
2
3
4
5
6
7
8
9
10
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()});
sub suchen {
my $such = $e->get();
...
}
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()
}
|< 1 2 >| | 19 Einträge, 2 Seiten |