in reply to DBI fetchrow_array problems

Can anyone suggest what is going on here and/ or an alternative solution that will preserve the database order within the per script?

It looks like you've got a mistaken idea in your head. There is no inherent order to the rows of a table in a database unless you explicitly order them. I.e. there is no such thing as "the database order". So, what you need to do is add an ORDER BY clause to your SELECT statement such that the rows are always output in the order you desire.

update: I just re-read your post and it appears that you're relying on some ordering relation that isn't described in the database. For instance, perhaps you believe that the order you get from your SELECT statement is the order of insertion into the table. It may happen to be the insertion order, but unless you've got a field that indicates that order, there's no reliable way to retrieve rows in that order.

If this is the case, then no amount of ORDER BY will help you, until you modify the structure of your table.