md2d Posted October 1, 2007 Share Posted October 1, 2007 i have 2 parameters: $start_date and $end_date, How do I get list project in a range start_date and end_date ? this query view all project, $que = "SELECT project_id, project_company, project_name FROM projects WHERE project_start_date >='$start_date' AND project_end_date <='$end_date' OR project_start_date <='$start_date' AND project_end_date <='$end_date' OR project_start_date <='$end_date' AND project_end_date >='$end_date' OR project_start_date <='$start_date' AND project_end_date >='$end_date' ORDER BY project_company ASC"; but i need to view in a range $start_date and $end_date |-------?--------| $start_date <----range------> $end_date anyone know, please help me thanks. ---- md2* Link to comment https://forums.phpfreaks.com/topic/71317-solved-sql-query-with-4-condition/ Share on other sites More sharing options...
fenway Posted October 1, 2007 Share Posted October 1, 2007 You where clause will currently return pretty much all combinations of start/end... so why include it? For the "true" range, use BETWEEN. Link to comment https://forums.phpfreaks.com/topic/71317-solved-sql-query-with-4-condition/#findComment-358986 Share on other sites More sharing options...
md2d Posted October 2, 2007 Author Share Posted October 2, 2007 $que = "SELECT project_id, project_company, project_name FROM projects WHERE ((project_start_date >='$start_date' and project_end_date <='$end_date') or (project_start_date <='$end_date' and (('$end_date' <= project_end_date) and (project_end_date <='$end_date'))) or ((('$start_date' <= project_start_date) and (project_start_date <= '$end_date')) and project_end_date >= '$end_date') or (project_start_date <='$start_date' and project_end_date >='$end_date') and project_active='1') ORDER BY project_company ASC"; thanks for reply fenway.......... Link to comment https://forums.phpfreaks.com/topic/71317-solved-sql-query-with-4-condition/#findComment-359955 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.