0

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

1
  • You need a better SQL query apparently. Commented Nov 9, 2009 at 16:44

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Without getting into details the situation does not alow me to be more specific.
2

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 

2 Comments

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
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.