payling
payling

Reputation: 2524

php return a specific row from query

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

Upvotes: 0

Views: 594

Answers (2)

Tomalak
Tomalak

Reputation: 338406

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.

Upvotes: 3

Ivan Nevostruev
Ivan Nevostruev

Reputation: 28753

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 

Upvotes: 2

Related Questions