Gossamer Forum
Home : General : Databases and SQL :

mysql select issue

Quote Reply
mysql select issue
i wonder if mysql has a ready statement which will select data and list by block or batch.

for example


select myvalue from tablename

the result will be
value1
value2
value3
value4
value5
value6
value7
............



what i expect is ( 3 value in batch)

value1,value2,value3
value4,value5,value6
value7,value8,value9
.........


or i have to parse the result again?

any help will be apprecaited.

Thanks
Quote Reply
Re: [biao] mysql select issue In reply to
Consider using selectcol_arrayref or one of the selectall_* methods in conjuction with a limit clause in a loop. Have a look at http://search.cpan.org/~timb/DBI/DBI.pm for the documentation on this feature.

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [biao] mysql select issue In reply to
In Reply To:

select myvalue from tablename

try...

select value1, value2, value3 from tablename;

r
Quote Reply
Re: [fuzzy logic] mysql select issue In reply to
Thanks fuzzy logic and ryel01

It seems that Fuzzy is more approaching.

From that manual : i found
The selectcol_arrayref method defaults to pushing a single column value (the first) from each row into the result array.

what i want is to :

pushing a triple value in a block into the result array.
in perl, i can use "join" . i just do not know how to do that in mysql syntax.

for example
select id, email from mytable


result i needed:

id1,id2,id3, email1,email2,email3
id4,id5,id6, email4,email5,email6
id7,,id8,id9, email7,email8,email9
..............






i just need a sample to show me show me how it works.

Thanks
Quote Reply
Re: [biao] mysql select issue In reply to
Are you literally wanting results returned as "id1, id2, id3 email1, email2, email3", or do you want "id1, email1 id2, email2 id3, email3"? if you're wanting "id1, email1", then this should work:

Code:
my $limit = 3;
my $offset = 0;

my $total = $dbh->do(qq(select count(*) from foo where col1 like "val"));

while ($offset <= $total) {
my $set = $dbh->selectall_arrayref(qq(select col1, col2 from foo where col1 like "val" limit $offset, $limit),);

foreach my $rec (@$set) {
print "col1: $rec->[0]; col2: $rec->[1]\n";
}

$offset += $limit;
}

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] mysql select issue In reply to
Thank you