Results 1 to 4 of 4

Thread: Display values in tablefields after assigning to varnames

  1. #1
    Join Date
    Mar 2003
    Location
    Chennai, India
    Posts
    25

    Display values in tablefields after assigning to varnames

    Hello All,

    I want to display field values in a table after assigning them to variable names. How is this possible. I tried fetchrow_arrayref and fetchall_arrayref. All I need is to diplay in a table column in webpage. Help me with a sample code, if possible, asapHelp me

    Thanks in advance
    Karthikeyan

  2. #2
    Join Date
    Mar 2003
    Location
    Chennai, India
    Posts
    25

    Solution here!!!

    After setting the connection up:
    -------------------------------

    while(my $ref = $sth->fetchrow_arrayref
    {
    my ($f1,$f2,$f3) = @{$ref};

    my $table = $query->startTable(COLS=>[gettext("f1"),
    gettext("f2"),
    gettext("f3") ] );

    $table .= $query->addTableLine(DATA=>[
    $f1,
    $f2,
    $f3 ] );
    }
    $table .= $query->endTable();

    This works fine for me. Any other solution is also welcome.

  3. #3
    Join Date
    Feb 2003
    Location
    Johannesburg, South Africa
    Posts
    145
    I prefer this skeleton:

    Code:
    $sql = "SELECT f1,f2,f3 FROM tablename";
    $sth = $dbh->prepare( $sql );
    $rv = $sth->execute;
    
    if ( $rv =~ /^0E0/ ) {
    
    	# error routine here - we did not receive anything from mysql...
    
    } else {
    
    	while ( ( $retval1, $retval2, $retval3 ) = $sth->fetchrow_array() ) {
    	
    		# do whatever with the vars here
    	
    	}
    
    }
    As you can see, it has a built in error checking for cases where we do not receive anything from MySQL ( empty result ).

    Cheers

  4. #4
    Join Date
    Mar 2003
    Location
    Chennai, India
    Posts
    25

    Thanks a many

    Hi Nico,

    Thx fow error checking mechanism. I can now implement in my project at all places.

Posting Permissions

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