如何使PHP / SQL查询选择列不等于变量的行

时间:2014-05-07 16:22:53

标签: php sql sql-server row where

我正在尝试使用PHP对MSSQL表进行查询,该表将找到列不等于某个值的行。

我目前正在使用这个:

  $selecting6 = "select * from used_trailers1 where photo1='".$picature2."' or photo='".$picature2."' or name='".$picature2."' or photo2='".$picature2."' or photo3='".$picature2."' or photo4='".$picature2."' and Orderid isnot '".$id."'";

无效,此代码无效。

可以使用哪些正确的代码来选择不具有$id的值的行?

感谢您的帮助。感谢所有帮助。

2 个答案:

答案 0 :(得分:1)

试试这个

$selecting6 = "select * from used_trailers1 where (photo1='".$picature2."' or photo='".$picature2."' or name='".$picature2."' or photo2='".$picature2."' or photo3='".$picature2."' or photo4='".$picature2."') and Orderid !='".$id."'";

答案 1 :(得分:1)

SQL标准中的不等运算符是<>但MySQL和SQL Server也支持!=。阅读Comparison Operators in SQL Server Comparison Functions and Operators in MySQL

SELECT [*] FROM [tbl] WHERE id <> $id
相关问题