开发者

php return a specific row from query

开发者 https://www.devze.com 2022-12-11 10:13 出处:网络
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.

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 o开发者_C百科nly 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


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.


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 
0

精彩评论

暂无评论...
验证码 换一张
取 消