473,466 Members | 1,439 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Simple fast way to grab the highest ID from a MySQL table?


I have a MySQL table on my web server (external web host) that has an
auto-increment integer as it's primary key field.

Is there a quick PHP function that will get me the highest ID in the table,
that is, the ID that belongs to the last record added.

Note, I need it to work across and between connection session, not from
within the same connection session.

thx

--

Robert Oschler
"Let the web hear you, add your voice to your web site in minutes!"
-- http://audiodirect.spiderchase.com/
(For a limited time, free voiceover with every sign-up, use this link
instead)
-- http://audio.spiderchase.com/
(A song - are you blue?)
-- http://bluedreams.spiderchase.com/
Jul 19 '05 #1
4 10451
BDR
~Select uniqueid from table order by uniqueid DESC~

Just run the query once and it'll give you the highest record if you
substitute `uniqueid` and `table` with the correct values. Afaik,
there's no function for php that maintains state variables of database
fields, (unless you write one).

Robert Oschler wrote:
I have a MySQL table on my web server (external web host) that has an
auto-increment integer as it's primary key field.

Is there a quick PHP function that will get me the highest ID in the table,
that is, the ID that belongs to the last record added.

Note, I need it to work across and between connection session, not from
within the same connection session.


Jul 19 '05 #2
BDR
~Select uniqueid from table order by uniqueid DESC~

Just run the query once and it'll give you the highest record if you
substitute `uniqueid` and `table` with the correct values. Afaik,
there's no function for php that maintains state variables of database
fields, (unless you write one).

Robert Oschler wrote:
I have a MySQL table on my web server (external web host) that has an
auto-increment integer as it's primary key field.

Is there a quick PHP function that will get me the highest ID in the table,
that is, the ID that belongs to the last record added.

Note, I need it to work across and between connection session, not from
within the same connection session.


Jul 19 '05 #3
Do a search for "Select Last_Insert_ID()" in the manuals.

That will retrieve the last ID in an auto_increment field.

"Robert Oschler" <no_replies@fake_email_address.invalid> wrote in message
news:wJ******************@news2.news.adelphia.net. ..

I have a MySQL table on my web server (external web host) that has an
auto-increment integer as it's primary key field.

Is there a quick PHP function that will get me the highest ID in the table, that is, the ID that belongs to the last record added.

Note, I need it to work across and between connection session, not from
within the same connection session.

thx

--

Robert Oschler
"Let the web hear you, add your voice to your web site in minutes!"
-- http://audiodirect.spiderchase.com/
(For a limited time, free voiceover with every sign-up, use this link
instead)
-- http://audio.spiderchase.com/
(A song - are you blue?)
-- http://bluedreams.spiderchase.com/

Jul 19 '05 #4
Do a search for "Select Last_Insert_ID()" in the manuals.

That will retrieve the last ID in an auto_increment field.

"Robert Oschler" <no_replies@fake_email_address.invalid> wrote in message
news:wJ******************@news2.news.adelphia.net. ..

I have a MySQL table on my web server (external web host) that has an
auto-increment integer as it's primary key field.

Is there a quick PHP function that will get me the highest ID in the table, that is, the ID that belongs to the last record added.

Note, I need it to work across and between connection session, not from
within the same connection session.

thx

--

Robert Oschler
"Let the web hear you, add your voice to your web site in minutes!"
-- http://audiodirect.spiderchase.com/
(For a limited time, free voiceover with every sign-up, use this link
instead)
-- http://audio.spiderchase.com/
(A song - are you blue?)
-- http://bluedreams.spiderchase.com/

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Seth | last post by:
I want to create a simple hash function that can hash strings. Currently I'm storing passwords as strings in a DB but want to store them as a hash. I don't need any proper standardised hashing e.g....
2
by: Tim Fountain | last post by:
We've recently enabled slow query logging on a server and it's proving interesting seeing which queries are bogging things down. This one is puzzling me a little: SELECT articleid, type,...
3
by: Vinod Bhaskar | last post by:
Hi Friends, In my linux server (LOCAL),  accessing data through the PHP scripts from MySQL (3.23.41)tables, it is taking more time.   Earlier it was very fast.   Now a days some reports it is...
0
by: Jesse Sheidlower | last post by:
I'm struggling with speed issues on some queries that I would have expected to be relatively fast. Perhaps even more frustratingly, when I've tried to break these down into their components, they...
0
by: Robert Oschler | last post by:
I have a MySQL table on my web server (external web host) that has an auto-increment integer as it's primary key field. Is there a quick PHP function that will get me the highest ID in the table,...
3
by: 42 | last post by:
Hi, I've run into a block, that I'm almost sure is really simple...but I can't seem to clue in right now. I'd like to create a user control that takes input like this: <mycontrol:panel...
1
by: www.web20developers.com | last post by:
http://www.web20developers.com http://www.web20developers.com/index.php?option=com_content&task=view... Ajallerix : AJAX, simple, fast Web image gallery demo ; at Novell AJAX -...
7
by: eselk | last post by:
I'm doing some speed tests. I created a brand-new table, with just one "Long Integer" field. I'm testing adding 1000 records. If I use the "Export" feature in Access, it takes only a few seconds...
4
by: aadsaca | last post by:
i have a table w/ ff fieldname table name:elections here's the example contents of my table: Candidate_name Arjel Joseph Gloria Arjel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.