Hi Monks,
I've recently written a CGI script which queries a database and displays information about a user, however i now want to be able to only display columns in a table which contain a value other than "NA".

I wrote some code to do this, however it doesn't seem to be deselecting columns that contain all rows with the value "NA".

Also this code seems really bloated and bad.
Any help would be much appreciated.
Here is the code:
#!/usr/bin/perl use DBI; my $listname = shift; my @fieldlist = qw/S_FName S_SName S_Address S_Postcode S_State S_Coun +try S_Email S_Company/; my $field = (); foreach $field (grep(not_NA($listname,$_), @fieldlist)){ print "<td ALIGN=Left>".$field . "</td>"; } sub not_NA { my $listname = shift; my $field = shift; chomp $field,$listname; my $mid = lookup_MID($listname); my $db = "nMail"; my $sock = "/tmp/mysql.sock"; my $user = "user"; my $pass = 'password'; my $dsn = "DBI:mysql:$db;mysql_socket=$sock"; my $dbh = DBI->connect($dsn,$user,$pass); my $sth = $dbh->prepare("SELECT $field from ML_Subscribers WHE +RE MID = $mid"); $sth->execute() || die "Error: Could not get mailing list data +\n"; while (my @row = $sth->fetchrow_array) { if($row ne 'NA'){ $sth->finish(); $dbh->disconnect(); return 1; } } $dbh->disconnect(); return 0; } sub lookup_MID { my $listname = shift; chomp $listname; my $db = "nMail"; my $sock = "/tmp/mysql.sock"; my $user = "user"; my $pass = 'password'; my $dsn = "DBI:mysql:$db;mysql_socket=$sock"; my $mid = (); my $dbh = DBI->connect($dsn,$user,$pass); my $sth = $dbh->prepare("SELECT MID,Mname FROM ML_Lists"); $sth->execute() || die "Error: Could not get mailing list data +\n"; while (my @row = $sth->fetchrow_array) { chomp $row[0],$row[1]; if($row[1] eq $listname){ $mid = $row[0]; } } $dbh->disconnect(); if(!$mid){ return 0; } return $mid; }
Thanks for your input.

Neil Archibald
- /dev/IT -

In reply to CGI Table Column Selection by devslashneil

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.