snowdog Posted September 7, 2006 Share Posted September 7, 2006 if($show->level == 2){ $query = "select * from call_reminder WHERE (date >= '$todays_date' AND date <= '$max_date' AND level <= '$show->level') OR (member_group = '$show->mastermind' AND call = 'mastermind') ORDER by date, time"; $result_group = mysql_query($query) or die('Query failed: ' . mysql_error()); echo $query;}On my echo I get :[color=red]select * from call_reminder WHERE (date >= '2006-09-07' AND date <= '2006-10-22' AND level <= '2') OR (member_group = '1001' AND call = 'mastermind') ORDER by date, time [/color] All values are correct, but the logic is not working. The dates work, the level works, but it is bringing up all 3 mastermind calls instead of just 1001's call.I am at a loss here. Do I have too many variables in the query?Snowdog Quote Link to comment https://forums.phpfreaks.com/topic/20032-sql-query-issue/ Share on other sites More sharing options...
wildteen88 Posted September 7, 2006 Share Posted September 7, 2006 Remove the parenthesises from your query so its just this as the query:[code]select * from call_reminder WHERE date >= '2006-09-07' AND date <= '2006-10-22' AND level <= '2' OR member_group = '1001' AND call = 'mastermind' ORDER by date, time[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20032-sql-query-issue/#findComment-87875 Share on other sites More sharing options...
snowdog Posted September 7, 2006 Author Share Posted September 7, 2006 did that and is the same result :(Snowdog Quote Link to comment https://forums.phpfreaks.com/topic/20032-sql-query-issue/#findComment-87876 Share on other sites More sharing options...
HuggieBear Posted September 7, 2006 Share Posted September 7, 2006 Your date column is of type 'date' in the database is it?RegardsRich Quote Link to comment https://forums.phpfreaks.com/topic/20032-sql-query-issue/#findComment-87880 Share on other sites More sharing options...
wildteen88 Posted September 7, 2006 Share Posted September 7, 2006 Are you getting an error?What happens if you add this:[code]$row = mysql_fetch_assoc($result_group);echo '<p><pre>' . print_r($row, true) . '</pre><p>';[/code]After echo $query; Quote Link to comment https://forums.phpfreaks.com/topic/20032-sql-query-issue/#findComment-87881 Share on other sites More sharing options...
Barand Posted September 7, 2006 Share Posted September 7, 2006 Well we could sit here all day guessing about your logic. All we know is what doesn't work.Now if we knew what you had, and the records you expect to retieve from those, it might give us more of a clue so we can come up with the correct logic. Quote Link to comment https://forums.phpfreaks.com/topic/20032-sql-query-issue/#findComment-87890 Share on other sites More sharing options...
HuggieBear Posted September 7, 2006 Share Posted September 7, 2006 Try this...[code]$query = "select * from call_reminder WHERE date(date) >= '$todays_date' AND date(date) <= '$max_date' AND level <= '$show->level') OR (member_group = '$show->mastermind' AND call = 'mastermind') ORDER by date, time";[/code]If that doesn't work, then post your code as previously suggested.Rich Quote Link to comment https://forums.phpfreaks.com/topic/20032-sql-query-issue/#findComment-87897 Share on other sites More sharing options...
snowdog Posted September 7, 2006 Author Share Posted September 7, 2006 OK I got it.The first part of the logic was calling in the call that i wanted to only pull up by the mastermind number in the second half of the query.So the calls I wanted to eliminate where already in the qiery and that is why the 3 calls came up when only one should have. So I fhad to eliminate the calls that I wanted to then run logic on in the second half of the query and it now works. Thanks all.Here is the working query: if($show->level == 2) { $query = "select * from call_reminder WHERE date >= '$todays_date' AND date <= '$max_date' AND level <= '$show->level' AND [color=red]member_group < 1000 [/color] OR member_group = '$show->mastermind' AND call = 'mastermind' ORDER by date, time"; $result_group = mysql_query($query) or die('Query failed: ' . mysql_error()); } Quote Link to comment https://forums.phpfreaks.com/topic/20032-sql-query-issue/#findComment-87902 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.