in reply to A unique question help!
$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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: A unique question help!
by Anonymous Monk on Oct 14, 2009 at 17:34 UTC | |
|
Re^2: A unique question help!
by Anonymous Monk on Oct 14, 2009 at 17:45 UTC | |
by kennethk (Abbot) on Oct 14, 2009 at 17:54 UTC | |
|
Re^2: A unique question help!
by Anonymous Monk on Oct 14, 2009 at 17:41 UTC |