Here is my problem.
I need more than one row from the database, and i need the first row for certain task and then go through all the list again to create a record set.
$query = "SELECT * FROM mytable";
$result = mysql_query($query);
$firstrow = //extract first row from database
//add display some field from it
while($row = mysql_fetch_assoc($result)) {
//display all of them
}
Now, how to extract just the first row?
解决方案
Using mysql_fetch_assoc() not only fetches a row, it also moves the internal pointer of the result set to the next row. To reset the result resource to the first row, you need to use mysql_data_seek().
$query = "SELECT * FROM mytable";
$result = mysql_query($query);
$firstrow = mysql_fetch_assoc($result);
// reset the result resource
mysql_data_seek($result, 0);
while($row = mysql_fetch_assoc($result)) {
//display all of them
}