Jump to content


Photo

SQL Query issue


  • Please log in to reply
7 replies to this topic

#1 snowdog

snowdog
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 07 September 2006 - 06:02 PM

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 :

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

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

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 07 September 2006 - 06:07 PM

Remove the parenthesises from your query so its just this as the query:
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


#3 snowdog

snowdog
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 07 September 2006 - 06:11 PM

did that and is the same result :(

Snowdog

#4 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 07 September 2006 - 06:14 PM

Your date column is of type 'date' in the database is it?

Regards
Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 07 September 2006 - 06:15 PM

Are you getting an error?

What happens if you add this:
$row = mysql_fetch_assoc($result_group);
echo '<p><pre>' . print_r($row, true) . '</pre><p>';
After echo $query;

#6 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 07 September 2006 - 06:21 PM

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.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#7 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 07 September 2006 - 06:34 PM

Try this...

$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";

If that doesn't work, then post your code as previously suggested.

Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#8 snowdog

snowdog
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 07 September 2006 - 06:39 PM

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 member_group < 1000 OR member_group = '$show->mastermind' AND call = 'mastermind' ORDER by date, time";    
      $result_group = mysql_query($query) or die('Query failed: ' . mysql_error());
    }




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users