I'm trying to run a simple query that returns all the results in a table.

   $query = db_query("SELECT name FROM {my_table}");
   $result = db_fetch_array($query);	
   echo db_num_rows($query);
   print_r($result);

When I run it and count the rows with db_num_rows, I get the correct number of rows; however, when I use db_fetch_array (or db_fetch_object for that matter), it only returns the first row. Does anyone have any idea what's happening here? Am I missing something?
I'd appreciate any help, because this is driving me nuts. Thanks!

Comments

nevets’s picture

Those functions fetch on row at a time so they are used something like

$results = db_query("SELECT ....");
while ( $data = db_fetch_object($results) ) {
  // Do something with data
}
tonyp001’s picture

I figured that the print_r() would reveal all the arrays. I guess not.
Thanks for the help!