0

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 _rowid is not a field of the table. Like this we need to get the record id from a result set in php mysql.

Ben
  • 4,392
  • 3
  • 23
  • 20

2 Answers2

4

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.

Community
  • 1
  • 1
Salman A
  • 262,204
  • 82
  • 430
  • 521
1

Check this function mysql_insert_id

Faraona
  • 1,685
  • 2
  • 22
  • 33