Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Mysql how to get the next highest to a value?
Old 09-23-2007, 07:39 AM Mysql how to get the next highest to a value?
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
hi,

i have been looking about and cant seem to find a answer so i thought i would ask you lot!

ok, i have a table which has dates in like 20092007 (20/09/2007) and i can use the max() in mysql to get the highest but how can i select the next highest value so if i have $cur_date and i want to select the date from the db which is the next highest when compared to $cur_date

Does this make sense?

Thanks
Dan

TP for good answers as usual
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
 
Register now for full access!
Old 09-23-2007, 07:55 AM Re: Mysql how to get the next highest to a value?
Skilled Talker

Posts: 96
Name: Tudor Barbu
Trades: 0
I don't think there's a simple and elegant way to do it, because MySQL compares string fields using the lexicographical order. That means that 01122007 (December 1st) will pe placed before 11012007 (January 11).
You should use the MySQL date format. It's simpler that way, because you have a bunch of usefull functions and procedures to get your job done. Look!
So try to convert the fields in your database, from strings (TEXT, VARCHAR) to dates (DATE, DATETIME).
__________________

Please login or register to view this content. Registration is FREE
Tudor.b is offline
Reply With Quote
View Public Profile Visit Tudor.b's homepage!
 
Old 09-23-2007, 08:27 AM Re: Mysql how to get the next highest to a value?
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
what about if i just had three fields (day month year)

Could it be done if it was in that format?
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-23-2007, 10:53 AM Re: Mysql how to get the next highest to a value?
coolkbk585's Avatar
Be good this Christmas!

Latest Blog Post:
KBlog has been deativated
Posts: 642
Name: Kyle
Location: Ada, MI
Trades: 0
Quote:
Originally Posted by dansgalaxy View Post
what about if i just had three fields (day month year)

Could it be done if it was in that format?
I think if you did that you'd have to write a special script just for that. I think it would be best to follow Tudor.B's advice and use MySQL to write the date in a database.
__________________
<?php if($Adsense_Revenue > 0): define('HAPPINES','100%'); else: define('HAPPINESS', '0%') endif; ?>
coolkbk585 is offline
Reply With Quote
View Public Profile Visit coolkbk585's homepage!
 
Old 09-23-2007, 12:31 PM Re: Mysql how to get the next highest to a value?
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
well i would also be writing a admin bit,
basically where it will be inputting entries and user can select the start and end date

Or more preferably, a start date and it automatically switches to the next one, on the next highest if the next highest date is >= current date.

so how could i do this with the mysql date thing.
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to Mysql how to get the next highest to a value?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15749 seconds with 12 queries