0

I have a scenario where I want to fetch records from my database table using SQL NOT operator and in the condition it doesn't negate two or more conditions but one; e.g

$sql1 = mysql_query("Select * from `".$dbTable17."` where `Dept`='$dept' AND NOT `Remark`='Error' ORDER BY `Date` ASC")or die("Error!~".mysql_error());

I assume you understand that the variables are already declared.

So, it doesn't fetch the records and I need a way to do it inside my while() loop construct.

halfer
  • 19,824
  • 17
  • 99
  • 186
Martin Stone
  • 21
  • 2
  • 5
  • 2
    `Dept = '$dept' AND Remark != 'Error'` or you could aslo use `<>` – AbraCadaver Sep 17 '15 at 19:51
  • @AbraCadaver...should i use this in my sql script or in php?...because its not working on my sql script...any other help please... – Martin Stone Sep 17 '15 at 19:56
  • If you can, you should [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) [statements](http://php.net/manual/en/pdo.prepared-statements.php) instead, and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Sep 17 '15 at 19:57
  • [Your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Jay Blanchard Sep 17 '15 at 19:57
  • OK Thanks...@JayBlanchard...please any solution to the gotchas? – Martin Stone Sep 17 '15 at 20:08

1 Answers1

0

Try this:

$sql1 = mysql_query("Select * from $dbTable17 where Dept='$dept' AND Remark!='Error' ORDER BY Date ASC")
    or die(mysql_error());
Dave Zych
  • 21,581
  • 7
  • 51
  • 66
  • its not working too...or do you have it working in your system?...why don't you look at my work and see for your self what am doing? – Martin Stone Sep 17 '15 at 20:59