This function has come in very handy with the developement of this site. You can use this function to set the data pointer to a certain row within your result that you recieve from a database function, in my case, mysql_query().
There are a couple reasons you would want to use the mysql_data_seek(). One would be to return to the first row returned from the database, or it could be used to return to any row. There are also other uses for this function but to keep it simple I will just talk about the first.
The following code is a standard mysql query created by dreamweaver.
mysql_select_db($database, $connection);
$query="SELECT * FROM tables;
$resource=mysql_query($query, $connection) or die(mysql_error());
$row_recordset= mysql_fetch_assoc($resource);
$totalRows_recordset = mysql_num_rows($resource);
When you request information from the database it is stored as a resource. You can then pull from that resource with the mysql_fetch_assoc($resource). You can also use other functions such as mysql_fetch_row($resource).
PHP handles a resource very similar to reading a file. As PHP reads from the resource, it marks its place, much like earmarking a page in a book PHP remembers the last spot that was read from the resource. When you get to the last page of the book, you turn back to page one, and when you get to the last of the resource you have to set the pointer back to the beginning.
mysql_data_seek("$resource",0);
$row_recordset=mysql_fetch_assoc($resource);
The mysql_data_seek() uses two values to accomplish this.The first value “$resource” is exactly what it says it is, the resource of your mysql select statement. The second is a numeric value of where you want to move the pointer or bookmark for that resource. The next time you get a value from the resource it will be from the new location of the pointer.
An important note if you are using dreamweaver. As you saw earlier in the code, dreamweaver initially sets $row_resource. With it initially set, you can use a do while loop so that the first instance is set and each reoccurring instance is set by the while statement. This is why after using the mysql_data_seek, I re-assigned $row_resource with the next value after the dataseek, in this case setting it back to the first value from the mysql select statement.