I run a query and get a result set. I need to get the nth record from this result set. Any ideas how I can do this?
I cannot select the nth record from the database directly coz I need to filter it and don’t know how many records there are in the result set. So I cannot be certain which number to pass to the mysql_result method i.e.
- Based on certain conditions, get a few rows from a table
- From these rows, select the nth row (the number n is not fixed. It depends on the number of records returned)
The basic idea is to get all results based on a set condition and get a random result from these.
Any ideas? Thanks.
Your question seems unclear. However here’s a guess:
You want to select the record in the middle:
Besides that, you can also do that if you have really less records:
and then you can use
$rs[N-1]to reach Nth record.Read
mysql_data_seekfrom PHP Manual if you will fetch just one record.