Is there any way to get the row id or row number from the result set in php mysql query? What is the use of _rowid in mysql?
The following query fetch the details of applicant 2435
SELECT * FROM applications WHERE _rowid =2435
but here _开发者_C百科rowid is not a field of the table. Like this we need to get the record id from a result set in php mysql.
Extracted from this question:
SELECT @row_number := NULL;
SELECT
@row_number := IFNULL(@row_number, 0) + 1 AS row_number,
Column1,
Column2,
ColumnN
FROM the_table
WHERE 1 = 1
ORDER BY Column1
If you are running this query from PHP, you need to execute the mysql_query()
function twice. First query would be SELECT @row_number := NULL
and second one would be the SELECT ...
query. Both queries must be executed together over same connection.
Check this function mysql_insert_id
精彩评论