How to navigate within a MySQL resultset

I have the results of a MySQL query obtained using PHP as follows
  $result = $handle->query( $query );

I can navigate from first to last record with a loop using
  $item = $result->fetch_assoc();

I need to know how to navigate freely among the records in the resultset.  
I have done recordset navigation in MS Access with VB and with Java.  Does PHP/MySQL support
moving the internal record pointer?  

Are there PHP functions for operating on $result other than fetch_assoc()?

I use mysqli( ... ) to make the database connection.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

try to use fetch_array instead of fetch_assoc to use number as index
Roger BaklundCommented:
Fetch all the records into an array, then navigate using the array.

$rows = array();
while($item = $result->fetch_assoc()) $rows[] = $item;

Yes, there are other functions, or rather "methods", as your $result variable is an instance of a class.

You can use data_seek() to navigate the result set directly, as an alternative to fetching everything in an array.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
crm-servAuthor Commented:
Thank you for the response.

How do I use 'number as an index'?  
NerdsOfTechTechnology ScientistCommented:
// where $result is query executed
$result = mysqli_query($conn, $query) or die ("Couldn't execute query.");

current($row) // current row; initialized as first record of array automatically
next($row) // next row
prev($row) // previous row row
end($row) // last row


 echo $row['fieldname']; // reference to a field within row. this loop iterated through all rows
 echo $count; // print count
 $count++; // increment count


print_h $row[2]; // print out the second row directly
crm-servAuthor Commented:
I was looking for the data_seek() kind of functionality.  Thanks for the help with this.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.