Hi Dan, I'm used to PostgreSQL, but using DBI, that shouldn't matter for what we're doing.
On Monday 30 Sep 2002 1:54 pm, dan wrote: > 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 __ $sth=$dbh->prepare("SELECT * from table;"); $sth->execute || die "select failed: $DBI::errstr"; while (@ary=$sth->fetchrow_array) { # do your stuff } I've not tested this, but that's all you should need to do. Gary > 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 -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]