Brian Coolidge
Brian Coolidge

Reputation: 4649

<> operator not working in query

Let's focus on event_table column. What I'm trying to do is getting all value except for "0"

enter image description here

Here is my query for that,

$query = "SELECT DISTINCT event_table FROM embedded_page WHERE event_table <> 0 AND uid='". $uid ."'";
$result = db_query($query);
foreach ($result as $r) {

    echo $r->event_table;
}

I'm trying to select event_table's values with distinct to prevent duplication. but since, I'm using the operator <> for some reason, it doesn't work. when I echoed it, no output

if I removed the event_table <> 0 it outputs 0, giveaway_table, and poll

Upvotes: 0

Views: 59

Answers (1)

Nathan
Nathan

Reputation: 10784

Try

 event_table <> '0'

You are comparing to a string column, but specifying an integer value, and it appears that either PDO or your underlying database is not handling the int to string conversion in the way you expect.

Also, your code sample is vulnerable to Sql Injection attacks.

Upvotes: 4

Related Questions