it seems that once db_fetch_object() executed for a db_query result, the result set removed. can the result set be retained and fetched again by db_fetch_object? is there any other ways to do so.

the fact is i m trying to count the number of db_query result and print out the result. in d5, there is a db_num_rows function but removed in d6. to count number of result in d6 using db_result(db_query(select count(*)...... will require the db to execute twice for the same sql query, that will lay more workload to the db server. using temp table is not allowed in some hosting service. how to avoid doing query twice to count and print the results?

thanks a lot.

Comments

darrenlambert’s picture

I think that the result set has a pointer, and once db_fetch_object has been called the pointer moves to the next record in the result set. If we could reset the pointer to the start, we could iterate again.

You can iterate the result set, using a counter to keep track of the number of records.
Using 'select count(*)' is silly, and more DB load, like you say.

HenryLTV’s picture

I'm having the same problem! Did anyone figure out a way to reset the db_fetch_object pointer within the Drupal Data Abstraction Layer? Some people pointed me to mysqli_result::data_seek but unfortunately I can't use this function within Bootstrap.inc since i'm limited to the Drupal Data Abstraction Layer.

Seems inefficient to me to query the DB a second time for the same data I already have in my result set =\

remco75’s picture

I'm having the same problem: does anybody have a workaroud?

It is strange indeed to do multiple query's when only 1 is needed!

remco75’s picture

I new there had to be something! drupal rules ;-)