Please use a meaningful subject line.  Your subject says absolutely 
nothing about the problem that you are facing.  If it wasn't the only 
message in my inbox, I might have deleted it without reading.

Read on for the solution.

On Mon, 1 Jul 2002, Poonam P wrote:

> I have written the following script after reading a
> Mysql book, but I am not able to understand as to how
> to fetch a given record no., or get records between a
> given range... like all records between 24th - 29th ..
> 
> A small part of the script...
> 
> #!/usr/bin/perl
> use DBI;
> use strict;
> my ($dsn)="DBI:mysql:test:localhost";
     ^^^^^^

don't put parentheses here.  use parens only when declaring a list of 
identifiers, like in the line just below.

> my ($dbh,$sth);
> my (@ary);
> my ($aaa);
> my ($bbb);
> 
> # Connect to databse
> $dbh = DBI-> connect ($dsn,{RaiseError=>1});
> 
> # Issue query
> $sth = $dbh -> prepare ("SELECT item1 from list1");
> $sth-> execute();
> 
> $bbb = $sth->fetchrow;
> $aaa = $sth->fetchrow;

to fetch the 25th row, you will first have to get the first 24 rows and 
discard them:

for my $i (1..24) {
        $sth->fetchrow;
}

$aaa = $sth->fetchrow;  # the 25th row


SQL does not allow you to select a particular record from a database.  
This is primarily due to the fact that unless you specify an ORDER BY 
clause in the SELECT statement, there is no specified order in which 
results will be returned.  They need not be returned in the same order 
that you inserted them.



-- 
The universe does not have laws -- it has habits, and habits can be broken.

_______________________________________________
http://mm.ilug-bom.org.in/mailman/listinfo/linuxers

Reply via email to