0

I have the following code that works great at constructing a query where a column is NULL as well as a few other criteria. The only problem is that I need to allow for the SPG_Suppress column to be empty. I've tried OR, AND and LIKE as well as range like > '' as found here.

I think I may have an issue with the syntax but can't narrow it down. Can someone show me the best way to construct this?

$res = mysql_query('SELECT * FROM ' . DB_TABLE
                    . ' WHERE SPG_Suppress IS NULL AND SPG_CallType = \'' . mysql_real_escape_string($callType) . '\'
                    AND SPG_Brand = \'' . mysql_real_escape_string($brand) . "'" . ' ORDER BY SPG_KeyWord ASC');
Community
  • 1
  • 1
Rocco The Taco
  • 3,695
  • 13
  • 46
  • 79
  • *Obligatory:* The `mysql_*` functions will be [deprecated in PHP 5.5](http://php.net/manual/en/faq.databases.php#faq.databases.mysql.deprecated). It is not recommended for writing new code as it will be removed in the future. Instead, either the [MySQLi](http://php.net/manual/en/book.mysqli.php) or [PDO](http://php.net/manual/en/book.pdo.php) and [be a better PHP Developer](http://jason.pureconcepts.net/2012/08/better-php-developer/). – Jason McCreary Jun 10 '13 at 14:54
  • I see this type of question all the time, you should read [common database debugging for PHP and MySQL](http://jason.pureconcepts.net/2013/04/common-debugging-php-mysql/). – Jason McCreary Jun 10 '13 at 14:55
  • try `(SPG_Suppress IS NULL OR SPG_Suppress = '')` instead of `SPG_Suppress IS NULL` – rcpayan Jun 10 '13 at 15:00
  • Thanks rcpayan...worked great. If you want to make this the answer I'll accept it. Good thread Jason, I'll check it out and book mark it. Thanks you both. – Rocco The Taco Jun 10 '13 at 15:07

0 Answers0