Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts

    problem in rendering a table to html

    I am trying to render some statistic results from a database onto a html. The first part works fine.

    Code:
    print "content-type: text/html \n\n";
    print "<html><head>\n";
    print "<title>Statistics</title>\n";
    print "</head><body>\n";
    
    print "<br/>";
    print " Statistics <br/><br/>";
    
    print "<table width=100% border='1'>";
    print "<tr><td>ab</td></tr>";
    But it seems that the table scripts after the below codes do not work. I tried something like this: print "<tr><td>ccc</td></tr>";

    Code:
    use constant INSTANCE => 'pro'; # XXX: 'test'
    my $pretty_dbname = ((INSTANCE eq 'pro') ? 'ABCD' :'Test');
    
    my $dbname = ((INSTANCE eq 'pro') ? 'abcd' : 'abcd_test');
    my $keyer = 'guest';
    my $password = 'guest';
    my $dbd = 'dbi:Pg:dbname=' . $dbname . ';host=arc';
    my $cmd;
    my $sth;
    
    my $dbh = DBI->connect($dbd, $keyer, $password) ||
        die "Couldn't connect to $pretty_dbname\: $DBI::errstr";
    
    for my $table1(qw(acc_status)){
    
    my $month2;
    
    for ($month2 = $month; $month2 >= 1; $month2--) {
    
    my $startmonth = $month2;
    my $startdate = "$year-$startmonth-1";
    
    my $endmonth = $month2+1;
    my $enddate = "$year-$endmonth-1";
    
    my $ide = 1;
    $cmd = qq{SELECT COUNT(*) FROM $table1 WHERE current_status = \'$ide\' and key1>=\'$start1\' and key1<\'$end1\';};
    
    $sth = $dbh->prepare($cmd);
    $sth->execute();
    my $count_new = $sth->fetchrow_array();
    
    my $ide2 = 4;
    $cmd = qq{SELECT COUNT(*) FROM $table1 WHERE current_status = \'$ide2\' and key1>=\'$start1\' and key1<\'$end1\';};
    
    $sth = $dbh->prepare($cmd);
    $sth->execute();
    my $count_ed    = $sth->fetchrow_array();
    
    print "<tr><td>$count_ed</td></tr>"
    
    }
    What am I missing here?

    Thanks.
    Last edited by camaross; 09-27-2011 at 06:50 PM.

  2. #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    3,296
    Thanks
    2
    Thanked 227 Times in 220 Posts
    $sth->fetchrow_array() returns a list, so the var that gets assigned the returned data needs to be in list context.

    note the parens around $count_ed
    Code:
    my ($count_ed)    = $sth->fetchrow_array();

  3. Users who have thanked FishMonger for this post:

    camaross (09-27-2011)

  4. #3
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts
    Thanks. But I have an impression that is not a problem. I tested the code without rendering a html earlier one. I has no problem. It prints one line at a time to my Perl screen.

    The problem with html is that even
    Code:
    print "<tr><td>test</td></tr>"
    does not work after the second set of code.


    Quote Originally Posted by FishMonger View Post
    $sth->fetchrow_array() returns a list, so the var that gets assigned the returned data needs to be in list context.

    note the parens around $count_ed
    Code:
    my ($count_ed)    = $sth->fetchrow_array();

  5. #4
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    3,296
    Thanks
    2
    Thanked 227 Times in 220 Posts
    Your impression is wrong, but the correction I pointed out may not be the only problem that needs fixing.

    "does not work" is a bad problem statement.

    In what way does it not work?

    Since you don't have any error handling on the db calls, how do you know that they are not failing?

  6. Users who have thanked FishMonger for this post:

    camaross (09-29-2011)

  7. #5
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    3,296
    Thanks
    2
    Thanked 227 Times in 220 Posts
    You're missing the semicolon on that print statement.

  8. Users who have thanked FishMonger for this post:

    camaross (09-29-2011)


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •