spiderzaur
spiderzaur

Reputation: 29

OR clause in Javascript function

I have a Javascript function which goes and searches Google Fusion table column values via search box field. I am trying to make it search multiple columns with OR clause but can not make it work.

function changeMap_1() {
  var whereClause;
  var searchString = document.getElementById('search-string_1').value.replace(/'/g, "\\'");
  if (searchString != '--Select--') {
    whereClause = "'Name' CONTAINS IGNORING CASE '" + searchString + "'";
  }
  layer_0.setOptions({
    query: {
      select: "col5",
      from: "1xTAvPva0-iIJo6UAKS1UuERYQTjdYZfvqOlIX_HM",
      where: whereClause
    }
  });
}

This is the function above. I have multiple "whereClause" values but everything else is the same.

whereClause = "'Name' CONTAINS IGNORING CASE '" + searchString + "'";

whereClause = "'Address' CONTAINS IGNORING CASE '" + searchString + "'";

whereClause = "'City' CONTAINS IGNORING CASE '" + searchString + "'";

How can i combine these "whereClause"s to say this OR this OR this...?

I tried the following two, but they didn't work.

whereClause = "'Name' CONTAINS IGNORING CASE '" || "'City' CONTAINS IGNORING CASE '"  + searchString + "'";

and

whereClause = "'Name' CONTAINS IGNORING CASE '" + searchString + "'" || "'Name' CONTAINS IGNORING CASE '" + searchString + "'";

Any thoughts?

Upvotes: 1

Views: 128

Answers (2)

spiderzaur
spiderzaur

Reputation: 29

Thank you guys for the tips. I ended up merging all the columns into new column and then do a search inside that new column since it contains data from all columns.

Upvotes: 1

shennan
shennan

Reputation: 11676

It looks like you're evaluating your OR statement before sending it as SQL. Could that be the issue?

Something like:

whereClause = "'Name' CONTAINS IGNORING CASE '" + searchString + "' | 'City' CONTAINS IGNORING CASE '" + searchString + "'";

Or like:

whereClause = "'Name' CONTAINS IGNORING CASE '" + searchString + "' OR 'City' CONTAINS IGNORING CASE '" + searchString + "'";

I'm not familiar with Google Fusion Tables but it looks like they have an SQL query style.

Upvotes: 0

Related Questions