0

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

Ferdinand.kraft
  • 12,579
  • 10
  • 47
  • 69
Wesley Brian Lachenal
  • 4,381
  • 9
  • 48
  • 81
  • try using `!=` instead of `<> ` – syrkull Apr 01 '13 at 05:49
  • @shnisaka what for? Are you sure `<>` doesn't work? – Your Common Sense Apr 01 '13 at 05:51
  • @Wesley To let you know, there is no `<>` operator in PDO – Your Common Sense Apr 01 '13 at 05:52
  • @YourCommonSense some databases do not support `<>` .. search for it and see for yourself – syrkull Apr 01 '13 at 05:53
  • 1
    @shnisaka, can you name one SQL database that doesn't support `<>`? I think I covered the major ones here: http://stackoverflow.com/questions/723195/should-i-use-or-for-not-equal-in-tsql/723426#723426 – Bill Karwin Jul 25 '13 at 01:49
  • @BillKarwin this question could help you with your research. http://stackoverflow.com/questions/4166966/what-is-the-point-of-the-diamond-operator-in-java-7 Also, if you you google "diamond operator not supported" you will see a bunch of different languages that do not support them. – syrkull Jul 25 '13 at 02:13
  • @shnisaka, that's about the Java generics diamond operator, not the "not equal to" operator in SQL. The google search you suggested shows only references to the Java generics diamond operator, and a diamond-operator notation in number theory, which also has nothing to do with with SQL. – Bill Karwin Jul 25 '13 at 02:18

1 Answers1

4

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.

Nathan
  • 10,593
  • 10
  • 63
  • 87