It is possible to select last row selected by mysql_query
in php without iterating using mysql_fetch_row
from first row till last?
If so, what should I use?
How about ORDER
-ing the results in reverse order and getting the first element? Will that work ? (If you are only interested in that row, you can also use LIMIT 1
)
You can use mysql_data_seek function:
$result = mysql_query($query);
$row_num = mysql_num_rows($result);
if (mysql_data_seek($result, $row_num - 1)) {
$row = mysql_fetch_assoc($result);
...
}
mysql_free_result($result);
Or, more simply this:
$count=mysql_num_rows(mysql_query("SELECT * FROM whatever"));
$query="SELECT * FROM whatever LIMIT ".($count-1).", 1";
print_r(mysql_fetch_array(mysql_query($query)));