I send select-clause to my database:
"Select ID,NAME from table orddr by name limit 0,20"

I get 20 rows order by nimi. How I get the row number
from specifig line ?

for example, if the resul of select-clause is:
id: name
223 Anders
224 Bertta
225 Ellen
226 Ivan
227 Jack
226 Karl
... ...

how I get row number from resultset, where name is Ellen ?

How to use functions mysql_data_seek(), mysql_store_result() in PHP code ??

    do you mean row number or the id of the row?

    If it is row number then you can simply use a counter as you go through the rows returned.

    $counter = 1;
    while($row = mysql_fetch_array($query))
    {
    print "row $counter\n";
    $id = $row['id'];
    $name = $row['name'];
    
    print "$id $name\n";
    $counter++;
    }
    

      if you want to single out the row:

      $counter = 1
      while($row = mysql_fetch_array($query))
      {
      $id = $row['id'];
      $name = $row['name'];

      if($name == "Ellen")
      {
      print "ID: $id, name: $name, row #: $counter \n";
      }
      $counter = $counter + 1
      }

        do you mean row number or the id of the row?

        I mean the row number. Filed ID have not same value what is the number of that row. Records are deleted also so ID and the number of the row is different.

        I can use $counter as you explained, but is there any funtion() in PHP, that returns the row number from resultset of select ?

          Nope.

          There really is no such thing as a row number in sql. It's often useful to think of a table as holding a list of records which implies that there is some kind of order. But in reality the database is free to store the records however it wants to and may in fact physically reorder them at will.

            What I do in order to retain integrity is to have a deleted field. In that way all of the ID's are retained and when something is deleted then it is possible to set this in the delete field. This is especially essensial when other tables are relying on the data. For example if you have a table of courses and users that can book onto them. If you delete a course in furture then you will lose the integrety of the user course history.

              Write a Reply...