Avatar

SQL call to find highest ID (General)

by Auge ⌂, Wednesday, August 24, 2011, 10:49 (4650 days ago) @ Alise

Hello

I want to know the highest ID of all the posts in my forum. I use the code below, and it works. But I wonder if it is an efficient way of doing it or if there's a better way. Thanks :-)


$result = mysql_query("SELECT id FROM <Change_to your_DB>.mlf2_entries ORDER BY id DESC LIMIT 0,1");
$highestID = mysql_result($result, 0);

Thus query is generally correct. If you use it in the context of the forum script, you use the existing connection to the forums database. So there's no need to declare the database name. The following version of the query should do the same as yours (only cosmetical changes).

SELECT id FROM mlf2_entries ORDER BY id DESC LIMIT 1

Tschö, Auge

--
Trenne niemals Müll, denn er hat nur eine Silbe!


Complete thread:

 RSS Feed of thread