Hey guys, I was wondering what the query is to return the current row # from a mysql database. I have a table that uses and auto incriment ID field to relate to some other tables but i'd like to select the actual row number based off of that unique id.

so say id 45 is the first in the table i'd like something like

Select ROWNUMBER from TABLE Where id=45;

and get the number 1 in result.

anyone know how to go about this?

    Records does not have any position/rownumber. There is no concept of first.

      If a table has X number of rows that can returned using a COUNT() then there should be a way of getting back the current position of a record. I know that using ado you could get the absoulte position of the record (even when connected to mysql using an odbc driver). So i know the capability is there i just would like to know how to access it via php.

        using php...

        $rown = 0;
        while($row = mysql_fetch_assoc($result))
        {
            $rown++;
            echo 'Position in result for row: ' .$row['id']. ' is pos: ' . $rown . '.<br>';
        }
        

        something like that... would work

          Select ROWNUMBER from TABLE Where id=45;

          You will be getting rows returned in an undetermined order. Add an order by.

          If a table has X number of rows that can returned using a COUNT() then there should be a way of getting back the current position of a record. I know that using ado you could get the absoulte position of the record (even when connected to mysql using an odbc driver). So i know the capability is there i just would like to know how to access it via php.

          absolute position, absolute page, etc. refer to the order in the returned recordset and not the physical order in the data pages.

            Write a Reply...