Hey guys.
I have a field in a table (pct_code_country) that saves in this array format [“CHI”,“ARG”]. These are country codes. This format is saved by a Tagify field when editing the product in the Back-end.
On the front-end I have a page with a filter on a tagify field that takes information from the pct_code_country field to filter but can only filter if the data is saved in this format: CHI. I’ve tried CHI, ARG… ‘CHI, ARG’ but it doesn’t filter. You can only filter if you have a country code in the field (CHI). Then it shows all products that have the CHI code.
Is there any way to take this array [“CHI”,“ARG”], separate it and use it in the filter?
I already did the entire registration system for these codes using the Tagify field and I didn’t want to have to do it again.
I stopped at this problem and I can’t move forward.
Perhaps I did not fully understand you, but I would do two things:
would bring all the values in the database to a single format like array [‘CHI’,‘ARG’] - now it seems that this is clearly not the case with you
it seems easier to me to send the filter value from Tagify to Server Action, where it forms an array, checking compliance with the conditions in a loop and returns a ready-made list to the front
Hello.
Thanks for the answer.
The pct_code_country field in the table is in the format [“CHI”, “ARG”].
What I need is to filter by the pct_code_country field and where it has the CHI code, for example, it shows all the products that have this code. But if the same product has the code CHI and ARG [“CHI”, “ARG”] it will show the products that have these codes.
What I’m not able to do is make the filter work with this array [“CHI”, “ARG”]. It only works if the field has a single code, CHI for example.
In the video I demonstrate what I need.
When selecting the country in the list, the filter only shows products that have the country code in the pct_code_country field.
If I select another country, it will complement the result.
This works perfectly with just one Country code in the pct_code_country field and in this format CHI or ARG or FRA. If I apply an array [“CHI”, “ARG”] to a product that is in Chile and also in Argentina, the filter does not work. This must be an array problem. I cannot return the result if it is in the array format [“CHI”, “ARG”].
outer loop using the filter passed as an input parameter in the form of an array
a loop through all the records of the table, inside which you check whether the required code is in the value from the table - if so, then add the value of the record to the List
after all the cycles, you get the value from the list into a variable for output - via Get Array List Value
A small correction - it’s better to make an outer loop through the table from the database, and an inner loop through the query array, and if there is at least the first match of a country, then you can exit the inner loop - make some kind of boolean flag for this - this way you will avoid duplicating records and it will be faster work
It’s a pretty convoluted way to do this really. Normalizing your database would really be better, but this works. LMK if you need more info on what’s happening.
Hello, @Heather_Mann .
Thank you very much for the tutorial. I’ve already replicated it here.
But this message appears in the browser debug:
“message”: “Array to string conversion”,
I saw this post but I confess I had doubts.
I usually do everything in PHP code and I’m migrating some projects and creating them from scratch in Wappler. I’m creating this from scratch, so I was very confused on how to apply that function to solve my problem.
A setValue step with outpur enabled, that outputs the $_GET.countries.split(’,’)
steps 5 and 6 are ready you got it.
We need our query…
I have a simple query that exports the id, name and the tags (JSON Array) of my products…
I suppose you can work the same way and build a query that outputs whatever fields you need ( complicated, joins whatever you need) JUST MAKE SURE TO INCLUDE the JSON Array column, I think you call it pcs_code_pais…
NO CONDITIONS needed for our main purpose (filter the countries by the tagify values). You can add any condition is necessary (dates, amounts, names of clients ) but don’t add any condition related to the JSON Array.
(This will be made client-side with the dmx.formatter)