mysql - PHP get last entry
829
So I need to find the last entry of my MySql table, I get the first one this way:
if($f4==0) { /*do this*/ } else { /*or do that*/ }
I have a table with incremented IDs, but it is sorted out by position like this:
$query="SELECT * FROM promotions ORDER BY position";
I would basicly need something like:
if($f4==Last row in table) { /*Do this*/ } else { /*Or do that*/ }
Answer
Solution:
If your table unique auto_increment column named
id
, you can just accomplish your task like this =>Answer
Solution:
Well, you should use SORT (DESC) and LIMIT 1 to get a specific row.
As in Matts comment, it is good practice to use a auto imcrement column (mostly primary key) for this (alternative: timestamp/rowversion)
The more costly version is an array of all values and get the total amount of fetched values via mysql_num_rows() and then just access the row from the array with the corresponding ID (-1 because it starts at 0 and not at 1 like the mysql_num_rows function)
Answer
Solution:
With a so vague question is difficult to see what you want to do really. Please provide some more code, don't worry, we won't steal it (;
In the meanwhile, you might want to see the MAX(), which could be useful.