Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] removing dupes from fetchrow_array()?

Expand Messages
  • Mike Southern
    See http://dev.mysql.com/doc/mysql/en/selecting-columns.html
    Message 1 of 2 , Mar 23, 2005
    • 0 Attachment
      See http://dev.mysql.com/doc/mysql/en/selecting-columns.html

      >
      > Following is the code used in my CGI script.
      >
      > my $query = $dbh -> prepare("SELECT * FROM invoices WHERE ID
      > = '$ID'");
      > $query -> execute();
      > while (my @row = $query -> fetchrow_array()){
      > print "$row[1] - $row[2] - $row[3]<br>";
      > }
      >
      > What If I want to remove dupes from @row? like if $row[2] is similar
      > in multiple records, only one entry should be showed, the duplicates
      > should not appear in the print.
      >
      > I am aware of grep, but unable to implement it here in While loop.
      >
      > @row = grep {++$count{$_} < 2} @row;
      >
      > I am also aware that Unique keys can be added within mySQL database,
      > but that's un-do-able due to some reasons. I want to remove dupes
      > within the script.
      >
      >
      > Any ideas?
    Your message has been successfully submitted and would be delivered to recipients shortly.