Forum Moderators: coopster
This question pertains to navigating result sets. I would like to avoid using the LIMIT clause, as I would have to re-run the same query to get the number of results without the clause, to allow me to:
Results [ 21 ] of [ 40 ]
Which seems rather wasteful.
Is there a way of returning an entire array of the results set that then I can get an index into. All the
mysql_fetch* functions seem to return only one row as an array. Where as I like to be able to reference a particular index without having to call
mysql_fetch* 'x' number of times to get that row. cheers,
asp
If you want only one field from a certain row you could use mysql_result [php.net] which lets you specify the row index directly.
Generally it is good practice to let the db engine do as much work as possible and to retrieve as little data from the db as you need. Limit PHP scripting. MySQL is better at manipulating large data sets than PHP.
If you only want to know the number of rows matching a certain criteria use count in your SQL statement.
Whatīs most efficient will depend on what exacly you are trying to do.
Andreas