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* Quote 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. Quote 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.......... Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.