Current location: Hot Scripts Forums » Programming Languages » PHP » Getting Highest Number


Getting Highest Number

Reply
  #1 (permalink)  
Old 02-24-04, 05:02 PM
CarBoffin CarBoffin is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Question Getting Highest Number

Hello,
I would like to get the highest number from a mysql table field called ID, add 1 to it and store the result number as a variable called $id.

Thanks

Last edited by CarBoffin; 02-24-04 at 05:31 PM.
Reply With Quote
  #2 (permalink)  
Old 02-24-04, 05:38 PM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
Wouldn't it be easier if you Auto-incremented the ID instead of reading the last ID and adding one to it?




Quote:
Originally Posted by CarBoffin
Hello,
I would like to get the highest number from a mysql table field called ID, add 1 to it and store the result number as a variable called $id.

Thanks
__________________
Reply With Quote
  #3 (permalink)  
Old 02-24-04, 05:42 PM
CarBoffin CarBoffin is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
hmm...

yes, i need to re-think what i'm doing...
Reply With Quote
  #4 (permalink)  
Old 04-07-04, 01:01 PM
nucking_futs nucking_futs is offline
New Member
 
Join Date: Apr 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Ok I do need to actually do this. I need to be able to add a number to only certain posts that a bulletin board makes. I have the part taken care of that defines which posts are which, but I really do need to do what was asked about originally.

I read something on max and array, but am not grasping it.

I am using PHP and MySQL.

Thanks!!
Reply With Quote
  #5 (permalink)  
Old 04-08-04, 01:20 PM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
You can use the "max" functions:


Code:
<?php
echo max(1, 3, 5, 6, 7); // 7
echo max(array(2, 4, 5)); // 5
?>
All you have to do is to read the values from your MySQL table column into an array, and feed that array to the "max" functions to find the highest value.





Quote:
Originally Posted by nucking_futs
Ok I do need to actually do this. I need to be able to add a number to only certain posts that a bulletin board makes. I have the part taken care of that defines which posts are which, but I really do need to do what was asked about originally.

I read something on max and array, but am not grasping it.

I am using PHP and MySQL.

Thanks!!
__________________
Reply With Quote
  #6 (permalink)  
Old 04-11-04, 01:34 PM
Apoc's Avatar
Apoc Apoc is offline
Newbie Coder
 
Join Date: Apr 2004
Location: UK
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
could you not just use the MAX function within SQL, ie:

select max(id) from table where constaints;

that would then return the highest number in that column?

HTH

<?Apoc?>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Serial number authentication geneane ASP 6 03-19-04 06:18 AM
Add an extension to a number from a database Bonzo PHP 2 02-20-04 11:38 AM
drop the lowest number TheLaughingBandit ASP 2 08-30-03 01:57 PM
BUG - number of members surebetdmg HotScripts Site Bug Reports 2 08-10-03 04:35 PM
auto number superman PHP 1 06-30-03 09:53 AM


All times are GMT -5. The time now is 09:04 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.