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.

The Database Forum


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



Reply
Old 08-26-2006, 12:44 PM problem with dates
sat
Novice Talker

Posts: 11
Trades: 0
Hi there,

I have a drop down list that holds the following options:
"today", "this week", "this month", "this year".

Is it possible to get records from a mysql database based on what the user chooses from the above drop down using only one query?

I know that using something like that:

SELECT * FROM table WHERE (month(DATEFIELD) = month(now()) and dayofmonth(DATEFIELD) = (dayofmonth(now())) and year(DATEFIELD)=year(now()));

I can retrieve today's records. So, one solution would be to create multiple queries and based on user input, execute the associated query. But given the fact that my form has various search criteria, i will end up with to many queries.

Any help would be very much appreciated.
Thanks.
sat is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-26-2006, 02:57 PM Re: problem with dates
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
you have to build the query "on the fly" depending on what the user chooses
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 08-26-2006, 03:53 PM Re: problem with dates
sat
Novice Talker

Posts: 11
Trades: 0
Thank you for the reply,

can you give me an example?
sat is offline
Reply With Quote
View Public Profile
 
Old 08-26-2006, 04:12 PM Re: problem with dates
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
probably, and there will be plenty of examples around in the forum for whatever serverside code you happen to be using.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 08-26-2006, 04:17 PM Re: problem with dates
sat
Novice Talker

Posts: 11
Trades: 0
I am using PHP.
Can i create a query on the fly using the IN clause;

I appreicate your help.
sat is offline
Reply With Quote
View Public Profile
 
Old 08-26-2006, 08:00 PM Re: problem with dates
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
PHP Code:
switch ($_POST['select_date']) {
  
  case 
1// This year
    
$fromDate mktime(00011date('Y'));
    break;
    
  case 
2// This month
    
$fromDate mktime(000date('n'), 1date('Y'));
    break;
    
  case 
3// This week
    
$fromDate time() - ( 60*60*24*(date('w'))  );
    break;
    
  default: 
// Today
    
$fromDate time();
    break;
}
$sql 'SELECT * FROM table WHERE datefield BETWEEN "' date('Y-m-d'$fromDate) . '" AND NOW()'
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to problem with dates
 

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.55548 seconds with 12 queries