Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get fetchrow result in one string

Status
Not open for further replies.

denis60

Technical User
Apr 19, 2001
89
CA
Hi everyone

Is it possible to get all the result of a fetchrow in one string or array like:

$result = $db->FetchRow();
or
@result = $db->FetchRow();

In VB they use getstring and getrows.

if not what is the fastest for each one.

Thanks in advence!
 
Is it possible to get all the result of a fetchrow in one string or array?
You don't say what module you're using, but I think fetchrow already returns an array, no?

If it returns an array and you want to make it into a string, use join, e.g.
Code:
while (my @result = $db->FetchRow()) {
    [b]my $string = join($delim, @result);[/b]
    # do something with $string
...
perldoc -f join

 
I think you want something like this:

Code:
	if ( $type eq 'array' ) {
		while ( my $row = $sth->fetchrow_arrayref() ) {
			push @result, [@{$row}];
		}
	} else {
		while ( my $row = $sth->fetchrow_hashref() ) {
			push @result, $row;
		}
	}

Where $type is defined as to whether you want to return an array containing records with a list of field values, or an array containing records with a hash of field name to value.

Barbie
Leader of Birmingham Perl Mongers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top