Jump to content

Archived

This topic is now archived and is closed to further replies.

snowdog

SQL Query issue

Recommended Posts

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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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;

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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());
    }

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.