in reply to mysql sorting
First:
SELECT group, somedata FROM table ORDER BY group, somedata
Next:
Update: I think setting $lastgroup initially to undef may be dangerous.. potenially a warning could be generated about using an undefined value in a comparison using the ne operator. So here is an update to the above routine that I think is safer:my $lastgroup = undef; while ( my $row = $sth->fetchrow_arrayref() ) { if ( $lastgroup ne $row->[0] ) { print( $row->[0] . "\n" ); $lastgroup = $row->[0]; } print( " " . $row->[1] . "\n" ); }
my $lastgroup = undef; while ( my $row = $sth->fetchrow_arrayref() ) { if ( ( !defined( $lastgroup ) ) || ( $lastgroup ne $row->[0] ) ) { print( $row->[0] . "\n" ); $lastgroup = $row->[0]; } print( " " . $row->[1] . "\n" ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: mysql sorting
by perleager (Pilgrim) on Jun 01, 2005 at 07:47 UTC |