Filtering database using two values into one text field

Hello,

I have a site I am building and I am trying to query city and state into one text field like Seattle, WA. Every time, I write Seattle and put the comma the query reject my demand; and when I add the state it does not work at all. When I type the city and space; the query disappear.

Can anyone help me with this, please. I tried every combination possible I am not seeing how to make it work.

You will need to use the spit() function to split the string into a two item size array then set them as separate conditions

Hello @Hyperbytes,

I tried different function of split, it is not working.
CountryName and City are in two different table in the database.
In the data picker of the condition, I can only select the $Get.location and there is no other array I can select in the filter. I am sure I am doing something wrong or I am not seeing.

If there is anyone who can outline the step for me it will be very useful.

Thank you again.

Not near a computer so cant actually check but from memory.

Use a set value stage to create the array

I.e. set value params = $_GET.searchstring.split(" ")

Your two strings will be in params[0] and params[1]

You may have to deal with what to do if only one word and space sent as referencing an undefined array parameter may cause an error. This should involve some if conditions and string checking, sure you can do that.

You may have to apoend the [0] parts manually

I tried to write the step and see if it will work. It is not. I even try to see with @TomD method too. I believe I am missing some step here. I am not sure which part.

Capture6

I will try to have a physical look into the problem when i get a chance but I am incredibly busy for the next few days so may take a while

Does it work if you don't include the comma? You can strip out unwanted characters (eg commas) before using them in the query. If this doesn't solve the problem, start by simplifying your query and getting it to work, before making it more complicated. The query you showed at the beginnig of this thread looks more complicated than necessary.

Yes, the query work if the comma is not there. However, it works only with one keyword if I try to write seattle, Wa it doesn’t work.
The input value does not give the result when I try to type two keywords from two different table.
Note: City has its own table and State has its own table. sometimes, user research for city and state by typing.
The simple query work with only one word but not with two words.

I will try some trick until you have time to get back to me. Thank you again and in advance

I meant will it work without the comma, even if you add a second word - eg ‘Seattle WA’?

No. it does not work if I add a comma or a space. I tried to replace or split on the data format and condition. I really don’t see it.

I realise this. But does it work if you don't include a comma?

Typing the city and the state doesn’t work. I can only type the city.
The query alone work without text filter. However, user might have want to look for the city and state.
When I type the City alone it works. When I type the State alone it works also. But when I try to type City and State. It does not work.

I'm still not clear if you have tried entering the City and State, without the comma. You started this thread, mentioning:

Have you tried without the comma? Eg 'Seattle WA' - not 'Seattle, WA'.

Not sure why your previous version did not work but try starting your server action with something like this to extract the two values of city and state (which you can examine if necessary via app connect server action success event)
NOTE this is cased on a space between, NOT a comma

image

Then use LocationCity CONTAINS {{city}} AND regionName CONTAINS {{state}}

Thank you for your input. I tried to do this
Capture
then
Capture2
I even remove the repeat step


It is not showing any query anymore.
I did change the condition as you requested.

It is not showing the query so I can’t even know if the filter works anymore.

@Hyperbytes I had to restart the step of the query you showed me. I guess the query was not showing because I wrote Get.location.split(’’’) instead of Get.location.split(" "). There was no space in the first get.
It is working now. However, I have one more issue;
When I type city like "Miami Florida "- it works.
However: When I type city “Miami Beach” it does not work.
Note: The first word works fine with the space but when I type something extra like Miami Beach. It does not.
I tried with Los Angeles too it is not working. When the city is two words the filter does not show. However, when it is only one word it works.
Thank you again for the first step. Thank you a lot.
Is there any solution you can give me for you the city with two words issue.

Yes, as a space is the delimiter then if you add a two word city the seconds word will be interpreted as the state and the third word (the state) ignored.

Many ways off resolving this and as is normally the case, the best solutions are the most complicated. Perhaps the easiest is to use a comma as the delimiter rather than a space although i would also suggest you add the trim function to remove any spaces from the start and end of the split values in case someone enters Miami Beach, Florida or similar

1 Like

I end up using this split: {{$_GET.location.trim().split(",")}}
Thank you for your help.
The split with separator comma allowed me to use two words with city and use the comma.
I can only write this way: “Miami Beach,Florida” I cannot write “Miami Beach, Florida” . The space after the comma stop the query from running As you stated.
It is not at far from what i was looking for. I really appreciate your help.

apply trim() to both split() items to remove any leading or trailing spaces and that will solve it

2 Likes