User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 455,991 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,771 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1263 | Replies: 7 | Solved
Reply
Join Date: Nov 2007
Posts: 99
Reputation: kings is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
kings's Avatar
kings kings is offline Offline
Junior Poster in Training

select query in mysql

  #1  
Dec 5th, 2007
hi
i have a table where dates and other info are getting inserted...
i have a form where the user can select a start date end date..
based on the start date and end date ..i want to retrieve all the content stored between these dates.....
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: select query in mysql

  #2  
Dec 5th, 2007
$sql="select * from table where (start_date between '$start_date' and '$end_date') or (end_date between '$start_date' and '$end_date')";

considering start_date and end_date are the columns of your table, the first condition will fetch the records if the start_date lies between the range of $start_date and $end_date (the user's input). similarly, it checks if end_date lies between the range.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Nov 2007
Posts: 99
Reputation: kings is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
kings's Avatar
kings kings is offline Offline
Junior Poster in Training

Re: select query in mysql

  #3  
Dec 5th, 2007
hi
i am doing attendance sheet..
wen the admin wants to check the attendance between two date then he will give the start and end date...
in the table there is one column for date...the table contain the user id(varchar) ,date(date),time(varchar)
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: select query in mysql

  #4  
Dec 5th, 2007
how does the admin enter the dates? does he have a form ? what is the name of those text fields ? basically, this will work.

$sql="select * from table where date between '$start_date' and '$end_date'";
$start_date and $end_date are post variables of the form.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Nov 2007
Posts: 99
Reputation: kings is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
kings's Avatar
kings kings is offline Offline
Junior Poster in Training

Re: select query in mysql

  #5  
Dec 5th, 2007
ya he is having a form the field names are day1 day2........the code tat u have sent id working....how to sort using single column un table
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: select query in mysql

  #6  
Dec 5th, 2007
using order by clause.

order by date asc | desc
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Nov 2007
Posts: 99
Reputation: kings is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
kings's Avatar
kings kings is offline Offline
Junior Poster in Training

Re: select query in mysql

  #7  
Dec 5th, 2007
thanks its working
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: select query in mysql

  #8  
Dec 5th, 2007
you are welcome!
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 9:35 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC