简体   繁体   中英

SQL- Query to select data using date selected using datepicker

I want to get data from database based on date selected using datepicker.

I am using the following query to get data between selected dated but what i need is like when i select from_date and to_date using datepicker and click a button i want all the data assocoated with the selected date to be displayed. What change should i make in the query (I think after Between ). Someone please help me. Thanks in advance. I want to use this with PHP as a server page.

SELECT
  EP.Employee_Id,
  TD.Training_Id,
  TD.Training_Date,
  DT.Topic_Name,
  EP.Employee_Name
FROM
  `training_details` TD 
  INNER JOIN `domain_topics` DT ON DT.Domain_Id=TD.Domain_Id 
  INNER JOIN `trainer_details` TRD ON TRD.Training_Id = TD.Training_Id
  INNER JOIN `employee_profile` EP ON TRD.Trainer_Id = EP.Employee_Id
WHERE
  TD.Training_Date BETWEEN '2012-12-01' AND '2012-12-31'; 

This might help: If you are using POST method:

SELECT  EP.Employee_Id, TD.Training_Id, TD.Training_Date, DT.Topic_Name, EP.Employee_Name 
FROM `training_details` TD
INNER JOIN `domain_topics` DT ON DT.Domain_Id=TD.Domain_Id 
INNER JOIN `trainer_details` TRD ON TRD.Training_Id = TD.Training_Id
INNER JOIN `employee_profile` EP ON TRD.Trainer_Id = EP.Employee_Id
WHERE TD.Training_Date >= '$_POST[from_date]' AND TD.Training_Date <= '$_POST[to_date]'; 

OR as in your query WHERE clause be like this:

WHERE TD.Training_Date BETWEEN $_POST[from_date] AND $_POST[to_date]

If you are using GET method, it will be:

WHERE TD.Training_Date BETWEEN $_GET[from_date] AND $_GET[to_date]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM