Dan,

In MySQL I don't know how you can do, but I believe that in theory is the same thing.

#!/usr/bin/perl

use Pg;
$db        = Pg::connectdb("dbname=database");
open (FILE, ">>/var/log/file.log");

$result = $db->exec("SELECT * FROM table;");
for($i=0;$i<$result->ntuples;$i++) {

    $id = $result->getvalue($i,0);
    $myid2 = $result->getvalue($i,1);
    $myid3 = $result->getvalue($i,2);
    print FILE "Line nº $i: $id - myid2 - myid3\n";

}
close(FILE);

Na Sunday, 29 de September de 2002 às 09:54:36 PM, dan escreveu:

> right, this is like an outline to what i want to be able to achieve..
> 
> ---------- my table ---------------
> row # : id , myid2 , myid3
> -----------------------------------
> row 1 : 1 , item 1 , item 2
> row 2 : 2 , item 3 , item 4
> row 3 : 3 , item 5 , item 6
> row 4 : 4 , item 7 , item 8
> ------------------------------------
> I'm using DBI mysql..
> 
> What i want to be able to do, is search through the table using the row
> number, rather than the column id, "myid1", "myid2", and "myid3". this is
> how i'm currently going through the database row by row to get all the
> information:
> 
> __ START __
> $id = 1;
> $sth = $dbh->prepare("SELECT * FROM table WHERE id=$id");
> $sth->execute;
> @ary = $sth->fetchrow_array;
> while ($ary[0] ne "") {
>     # here i set up the variables which contain the data from the table,
> which will be used later on,
>     $id++;
>     $sth = $dbh->prepare("SELECT * FROM table WHERE id=$id");
>     $sth->execute;
>     @ary = $sth->fetchrow_array;
> }
> __ END __
> that's all very well if all id's are there, but if say ID 2 was deleted
> because the information was no longer needed, the while loop would break
> straight after ID 1, since there's no data corresponding to ID 2. The table
> would end up like this:
> 
> ---------- my table ---------------
> row # : id , myid2 , myid3
> -----------------------------------
> row 1 : 1 , item 1 , item 2
> row 2 : 3 , item 5 , item 6
> row 3 : 4 , item 7 , item 8
> ------------------------------------
> what i want to be able to do is go through the table row by row and select
> all the data from each row, rather than have to select by id. any better
> clues now?
> 
> and how is it possible to find out how many rows a table has?
> 
> Dan
> 
> 
> "Cleiton L. Siqueira" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > Dear Dan,
> >
> > I don't know if I understood what you really want. Therefore I will try to
> help, ok.
> >
> > I use Postgres as Database.
> >
> > You can find out how many rows have in a table after you run a SQL like
> this.
> >
> > #!/usr/bin/perl
> >
> > use Pg;
> > $db        = Pg::connectdb("dbname=database");
> >
> > # This is a way to do it.
> >
> > $result = $db->exec("SELECT * FROM table;");
> > $number_of_row = $result->ntuples;
> > print $number_of_row;
> >
> > # This is another way to do it.
> >
> > $result = $db->exec("SELECT count(*) FROM table;");
> > $number_of_row = $result->getvalue(0, 0);
> > print $number_of_row;
> >
> > Best regards,
> >
> > Na Sunday, 29 de September de 2002 às 09:44:40 PM, dan escreveu:
> >
> > > How is it possible to cycle through an SQL table row by row, without
> having
> > > to increment an ID by 1 in a while loop and go
> > > SELECT * FROM table WHERE id=$id
> > > ?
> > > And how can I find out how many rows are in the table?
> > >
> > > Dan
> > >
> > >
> > >
> > > --
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> > >
> >
> >
> >
> > Cleiton L. Siqueira
> > Colégio Monjolo
> > [EMAIL PROTECTED]
> > (0xx45) 520-1915
> >
> > Esta mensagem foi enviada pelo sistema MONJOLO WEBMAIL
> >
> > http://www.colegiomonjolo.com.br
> >
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 



Cleiton L. Siqueira
Colégio Monjolo
[EMAIL PROTECTED]
(0xx45) 520-1915

Esta mensagem foi enviada pelo sistema MONJOLO WEBMAIL

http://www.colegiomonjolo.com.br


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to