Jump to content

[SOLVED] What's wrong with this query?


Moron

Recommended Posts

If I use this (Look at the EmailAddress part) :

 

$RESULTMEMBER=mssql_query("select distinct * from MemberInfo MI where BoardName='Traffic Safety Advisory Board' and EmailAddress != '' order by MI.[LName]");
$RESULTBPE=mssql_fetch_assoc($RESULTMEMBER);
$RESULTMEMBERCOUNT=mssql_num_rows($RESULTMEMBER);

 

... it acts like it should. But if I use this:

 

$RESULTMEMBER=mssql_query("select distinct * from MemberInfo MI where BoardName='Traffic Safety Advisory Board' and EmailAddress = '' order by MI.[LName]");
$RESULTBPE=mssql_fetch_assoc($RESULTMEMBER);
$RESULTMEMBERCOUNT=mssql_num_rows($RESULTMEMBER);

 

...it crashes.

 

The first query is where EmailAddress is NOT EQUAL to '' (null or blank). The second query is where EmailAddress IS blank.

 

So what's wrong here?

 

 

Link to comment
Share on other sites

= is not the comparisons you need here its ==

= really isn't a comparisons its more of saying x=6 or z=123 or f="sam I am"

== is a comparisons of values

=== checks value and type

 

 

But when I use ==, it crashes and gives me:

 

Warning: mssql_query() [function.mssql-query]: message: Line 1: Incorrect syntax near '='. (severity 15) in C:\user\WWWRoot\boards\TSAB\TSAB.php on line 15

 

Warning: mssql_query() [function.mssql-query]: Query failed in C:\user\WWWRoot\boards\TSAB\TSAB.php on line 15

 

Warning: mssql_fetch_assoc(): supplied argument is not a valid MS SQL-result resource in C:\user\WWWRoot\boards\TSAB\TSAB.php on line 16

 

Warning: mssql_num_rows(): supplied argument is not a valid MS SQL-result resource in C:\user\WWWRoot\boards\TSAB\TSAB.php on line 17

 

Warning: mssql_data_seek(): supplied argument is not a valid MS SQL-result resource in C:\user\WWWRoot\boards\TSAB\TSAB.php on line 19

 

Link to comment
Share on other sites

~cooldude

 

[pre]

                      +-----------+------------+

                      |    PHP    |  MYSQL    |

+----------------------+-----------+------------+   

|                      |          |            |

| Comparison operator  |    ==    |    =      |

|                      |          |            |

+----------------------+-----------+------------+

 

Link to comment
Share on other sites

~cooldude

 

[pre]

                       +-----------+------------+

                       |    PHP    |   MYSQL    |

+----------------------+-----------+------------+   

|                      |           |            |

| Comparison operator  |    ==     |     =      |

|                      |           |            |

+----------------------+-----------+------------+

 

 

But look at the query. It works fine with a single = sign and crashes with ==. My question is, why does it work where EmailAddress != and crashes when it DOES equal something?

 

Link to comment
Share on other sites

 

 

But look at the query. It works fine with a single = sign and crashes with ==. My question is, why does it work where EmailAddress != and crashes when it DOES equal something?

 

 

Can we have some clarification here?

 

Your original post said it crashed with "=", now you say it worked.

 

Which is it?

 

(And of course it failed with "==", as my last post stated for cooldude's benefit, that's the PHP comparison operator, not MySQL's)

Link to comment
Share on other sites

 

 

But look at the query. It works fine with a single = sign and crashes with ==. My question is, why does it work where EmailAddress != and crashes when it DOES equal something?

 

 

Can we have some clarification here?

 

Your original post said it crashed with "=", now you say it worked.

 

Which is it?

 

(And of course it failed with "==", as my last post stated for cooldude's benefit, that's the PHP comparison operator, not MySQL's)

 

Sorry about the confusion. If I only use....

 

where BoardName='Traffic Safety Advisory Board'

 

...it works fine. If I use....

 

where BoardName='Traffic Safety Advisory Board' and EmailAddress != ''

 

...it also works fine. But, I need it to use where EmailAddress DOES equal '' (blank).

 

Link to comment
Share on other sites

read this please.

 

http://dev.mysql.com/doc/refman/4.1/en/comparison-operators.html

 

BETWEEN ... AND ...  Check whether a value is within a range of values 
COALESCE() Return the first non-NULL argument 
<=> NULL-safe equal to operator 
= Equal operator 
>= Greater than or equal operator 
> Greater than operator 
GREATEST() Return the largest argument 
IN Check whether a value is within a set of values 
INTERVAL() Return the index of the argument that is less than the first argument 
IS NULL NULL value test 
ISNULL() Test whether the argument is NULL 
LEAST() Return the smallest argument 
<= Less than or equal operator 
< Less than operator 
LIKE Simple pattern matching 
NOT BETWEEN ... AND ... Check whether a value is not within a range of values 
!=, <> Not equal operator 
NOT IN Check whether a value is not within a set of values 
NOT LIKE Negation of simple pattern matching 
SOUNDS LIKE(v4.1.0) Compare sounds 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.