Moron Posted July 25, 2007 Share Posted July 25, 2007 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? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 25, 2007 Share Posted July 25, 2007 = 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 Quote Link to comment Share on other sites More sharing options...
Moron Posted July 25, 2007 Author Share Posted July 25, 2007 = 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 Quote Link to comment Share on other sites More sharing options...
Barand Posted July 25, 2007 Share Posted July 25, 2007 ~cooldude [pre] +-----------+------------+ | PHP | MYSQL | +----------------------+-----------+------------+ | | | | | Comparison operator | == | = | | | | | +----------------------+-----------+------------+ Quote Link to comment Share on other sites More sharing options...
Moron Posted July 25, 2007 Author Share Posted July 25, 2007 ~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? Quote Link to comment Share on other sites More sharing options...
Barand Posted July 25, 2007 Share Posted July 25, 2007 What error message do you get when it crashes (your original query, not the one with the erroneous ==) Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 25, 2007 Share Posted July 25, 2007 becouse you said the email is not equel to nothink Quote Link to comment Share on other sites More sharing options...
Barand Posted July 25, 2007 Share Posted July 25, 2007 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) Quote Link to comment Share on other sites More sharing options...
Moron Posted July 25, 2007 Author Share Posted July 25, 2007 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). Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 25, 2007 Share Posted July 25, 2007 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 Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 25, 2007 Share Posted July 25, 2007 where BoardName='Traffic Safety Advisory Board' and EmailAddress = ISNULL or where BoardName='Traffic Safety Advisory Board' and EmailAddress = NULL Quote Link to comment Share on other sites More sharing options...
Moron Posted July 25, 2007 Author Share Posted July 25, 2007 Thanks, folks. "IS NULL" did the trick! I swear I tried that earlier. Maybe I had the syntax wrong. Quote Link to comment 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.