Question

I am trying to make a Query for an MSSQL table using PHP that will find rows with a column that doesn't equal a certain value.

I am currently using this:

  $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."'";

To no avail, this code doesn't work.

What proper code can be used to select rows that don't have the value of $id?

Thank you for any help. All help is appreciated.

Was it helpful?

Solution

Try this

$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."'";

OTHER TIPS

Not equal operator in SQL standard is <> But MySQL and SQL Server also support !=. Read Comparison Operators in SQL Server Comparison Functions and Operators in MySQL.

SELECT [*] FROM [tbl] WHERE id <> $id
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top