Hi,
I am creating a table that displays users and their associated systems that they have access to. I am using two database tables in order to map information between them.
When a user uses my search bar, the bar uses that query to search a two column database for a matching user. It then uses the associated ID number and takes that ID number to query the other database for an associated system. The output of my queries should be a user with a system...
My problem is that I have users that have access to multiple systems (therefore, multiple IDs from the first database)...but then there are also IDs (systems) with multiple users that have access to it.
Here is the incomplete code I have in my fetch after the SQL command executes the initial search:
# Display content of search
while ( $ref = $sth->fetchrow_hashref()) {
# $uniqueKey is the column 'user' from the DB. (ie $key is the spec
+ific user name)
$key = $ref->{$uniqueKey};
# GetSystem uses the user name to get the associated ID number from
+ DB1, and uses that value to get an associated system name from DB2
my $systemKey = GetSystem($key);
if (exists $referenceTable{$key}) {
if (defined $referenceTable{key} eq $systemKey) {
# do i need to do this?
}
else {
push @{$referenceTable{$key}}, $systemKey;
}
} else {
push @{$referenceTable{$key}}, $systemKey;
}
}
my ($k,@v);
print "<table>";
print "<tr><th>User</th><th>System</th></tr>\n";
# SET UP THE TABLE
# EXECUTE THE WHILE LOOP
while (($k, $v) = each(%referenceTable)){
print "<tr><td>".$k."</td>";
print "<td>";
foreach (@$v) {
print "$_\n";
}
print"</td></tr>";
}
print"</table>\n";
I am pretty sure my if (exists) and if (defined) statements are wrong/not the best way...but if you have some sort of idea of how I can continue to search for associated ID numbers if there are multiple instances of a user in the database I would appreciate it. Thanks Monks!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.