I'm unclear why you cannot use
UNIQUE DISTINCT in your SQL query, but you can use a hash to check if you've seen a given data value already. You've not made it clear what you expect to be unique, but if you assume that "user" should only be displayed once, you might want something like:
$user_data = "
<table cellpadding=\"0\" cellspacing=\"0\">
<thead>
<tr>
<td colspan=\"4\">User List</td>
</tr>
</thead>";
my %seen;
for (my $i = 0; $i < @$sql_data; $i++) {
my $user = $sql_data->[$i]{user};
if ($seen{$user}) { # <-- added flow control
next;
}
$seen{$user} = 1;
my $link = "<a href=\"goto.pl?user=$user\">$user</a>";
my $first = $sql_data->[$i]{first};
my $last = $sql_data->[$i]{last};
my $phone = $sql_data->[$i]{phone};
my $mail = $sql_data->[$i]{mail};
$user_data = "$user_data<tr><td><div>$show</div></td><td><div>$las
+t, $first</div></td><td>$phone</td><td><div>$email</div></td></tr>";
}
$user_data = "$user_data</table>";
If your condition is more complex, you can use a list of lists (perllol) to check uniqueness in a parallel fashion.
Update: Changed UNIQUE to DISTINCT above. Not quite sure why I always forget that keyword. Thanks, roboticus.
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.