tags:

views:

74

answers:

2

Is it possible in php to return a specific row of data from a mysql query?

None of the fetch statements that I've found return a 2 dimensional array to access specific rows.

I want to be able to return only 1 specific row, kinda like mysql_result... except for entire row instead of 1 cell in a row.

I don't want to loop through all the results either, I already know how to do that I just thought that there might be a better way that I'm not aware of. Thanks

+2  A: 

You should add LIMIT to your mysql statement. And it will return only data you need. Like following:

-- returns 1 row after 2 row
SELECT * FROM table LIMIT 2, 1
Ivan Nevostruev
This works, I wish I had thought of this. I use limit all the time but it didn't occur to me to use it this time. Thanks Ivan
payling
You should always use a query that returns as few rows as needed. Doing this in the code instead of in the query is almost double-work.
T Pops
+3  A: 

For example, mysql_data_seek() and mysqli_stmt_data_seek() allow you to skip forward in a query result to a certain row.

If you are interested in one certain row only, why not adapt the query to return only the row you need (e.g. via a more specific WHERE clause, or LIMIT)? This would be more resource-effective.

Tomalak
Without getting into details the situation does not alow me to be more specific.
payling
This was less of a question, despite the question mark.
Tomalak