project3 Posted March 28, 2008 Share Posted March 28, 2008 Im using the between statement to find open restaurants in a db. the thing is it doesn't return result when the first number is equal so say restaurants open time is 5:00 to 10:00 if i say the current time is 5:00 I won't return a result until its 5:01. so is there a way i can say between and equal im not sure. I have my coded below. $query = "select * " . "from " . "ds_categories " . "where " . " ('$tnow' BETWEEN $thiscat AND $thiscat2 OR " . " '$tnow' BETWEEN $thiscat3 AND $thiscat4 OR " . " '$tnow' BETWEEN $thiscat5 AND $thiscat6) and " . " catID = '$v_c' AND " . " catHide != 'Y' " . "order by catSort " . ""; Thanks Link to comment https://forums.phpfreaks.com/topic/98360-between-statement/ Share on other sites More sharing options...
discomatt Posted March 28, 2008 Share Posted March 28, 2008 use more OR clauses $query = "select * " . "from " . "ds_categories " . "where " . " ('$tnow' BETWEEN $thiscat AND $thiscat2 OR " . " '$tnow' BETWEEN $thiscat3 AND $thiscat4 OR " . " '$tnow' BETWEEN $thiscat5 AND $thiscat6) OR " . " '$tnow' = '$thiscat' OR " . " '$tnow' = '$thiscat3' OR " . " '$tnow' = '$thiscat5' and " . " catID = '$v_c' AND " . " catHide != 'Y' " . "order by catSort " . ""; Link to comment https://forums.phpfreaks.com/topic/98360-between-statement/#findComment-503356 Share on other sites More sharing options...
project3 Posted March 28, 2008 Author Share Posted March 28, 2008 You probably need single quotes around your $thiscat variables in the query. it works just fine it returns results. the issue is that between only gets results between the two times and not if the time is the same Link to comment https://forums.phpfreaks.com/topic/98360-between-statement/#findComment-503359 Share on other sites More sharing options...
metrostars Posted March 28, 2008 Share Posted March 28, 2008 BETWEEN is inclusive. If it doesn't work then I'm not sure, you could try doing alot more or '$tnow' = ... Link to comment https://forums.phpfreaks.com/topic/98360-between-statement/#findComment-503362 Share on other sites More sharing options...
discomatt Posted March 28, 2008 Share Posted March 28, 2008 Modified. I reread. Link to comment https://forums.phpfreaks.com/topic/98360-between-statement/#findComment-503363 Share on other sites More sharing options...
project3 Posted March 28, 2008 Author Share Posted March 28, 2008 use more OR clauses $query = "select * " . "from " . "ds_categories " . "where " . " ('$tnow' BETWEEN $thiscat AND $thiscat2 OR " . " '$tnow' BETWEEN $thiscat3 AND $thiscat4 OR " . " '$tnow' BETWEEN $thiscat5 AND $thiscat6) OR " . " '$tnow' = '$thiscat' OR " . " '$tnow' = '$thiscat3' OR " . " '$tnow' = '$thiscat5' and " . " catID = '$v_c' AND " . " catHide != 'Y' " . "order by catSort " . ""; Awesome great idea! Link to comment https://forums.phpfreaks.com/topic/98360-between-statement/#findComment-503367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.