On Tuesday 01 Oct 2002 2:53 am, Hengky wrote: > > > 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? > > i hope this one can help you i'm using MySQL on my server > > $sth = $dbh->prepare("Select * from TableName;"); > $sth->execute; > > $countrow = 0; > while(@FieldTable = $sth->fetchrow_array()) { > # Do Some Action Here; > $countrow++; > } > > print "Total Existing Data on Table TableName = $countrow \n";
Nobody's mentioned: $countrow=$sth->rows; This way is more efficient that doing the 'select count(*)' as it's done from the same select query, and it also means that yo know beforehand how many rows you will be reading, which is often usefull, and is not possible if you use the countrow++ method. -- 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]