Count the number of times a tag appears in a database and add it to a pro gallery description.

So, I have a database that I categories each entry with a tag. These entries are displayed on dynamic pages. On the (All) page I have a filter to filter these.

I want to display each category on the homepage of my site, and when clicked upon, this will redirect to the (All) page and filter it.

I know how to create the filter, store the information using storage and then calling it on ready on the (All) page.

The problem I am having is counting how many times each tag (category) is used in the database, and then displaying this information on the homepage.

I discovered this site that does what I am looking for (I think it is using a Pro Gallery) -

If anyone could point me in the right direction, that would be incredibly helpful :facepunch:

Everything depends on the structure of your DATABASE. Since anybody has no clue how your DB is structured, i assume anybody will be able to give you the right answer.

I would know different ways of how a DB would/could look like (be structured), regarding your example.

@russian-dima My database has a few fields. Title, image, links etc. I also have a tag field. The tags are Farms, Wineries and Garden Centres.

I want to show Farms, Wineries and Garden Centres like the image above and then show the number of how many there. When it’s clicked on, then it goes to the (All) page and filters the

You have always just one TAG in each ROW ?

Is this the way you categorized all your institution?

Type:  STRING                  TYPE:TAG			        TYPE: STRING 

  1. title: VN-Winary category: Winery description: Best wine by Velo-Ninja
  2. title: NL-Winary category: Winery description: Best wine by Noah-Lovell
  3. title: VN-Farm category: Farm description: Biggest farm of Velo-Ninja
  4. title: NL-Farm category: Farm description: Smartest farm of Noah…
  5. title: Winary-X category: Winery description: Another-Winery
  6. title: Farm-A category: Farm description: Another-Farm
  7. title: Garden-Y category: Garden-C. description: Garden-Center-Y
  8. title: Winary-X category: Winery description: Another-Winery

@russian-dima Yes. Most of the time it is just one. Although there might be one or two where it has more than 1 tag.


How it can have more than one TAG?
If you would say → “i have in every row JUST 1 TAG”, i would ask you → why the hell you are using TAG-FIELD for CATEGORY ?

But because you have somewhere also more then just one VALUE → it makes more sense.

But how can a Winery also be a Garden-Center? Building-Complex with several stores inside?

@russian-dima I am using tags because some locations have more than one category.

The point is, I need to add this feature according to what I’ve already

However in your case you will want to use …

.hasSome('DB_FIELD_IDhere', ['value1', 'value2', and so on ....................])

I think the rest will be clear for you, because you seems to be someone who learn fast.

@russian-dima How do I add this to the Gallery? I need it to be like the site I’ve linked and the screenshot

Why → GALLARY ? → Why not REPEATER?

But should also not be a big problem …

Take a look at this one …
This is what a GALLERY expects as DATA-INPUT.

$w("#myGallery").items = [
    "type": "image",
    "title": "A View",
    "type": "video",
    "description": "Another beautiful view",
    "title": "Another View",

A simple ARRAY full of OBJECTS!
The same like a REPEATER would expect as DATA-INPUT.

@russian-dima Whichever is best for adding a category section like the image above. (Having looked at the site, I am assuming the image was built with the Pro Gallery)

I need to show 3 categories. The name of the category, and then the number of times that category appears in the database underneath.

When one of the categories is clicked on, I need it to redirect to the (All) page and filter it.

To be honest i never have touched a GALLERY at all, because i have my favourite → REPEATER, which i can modify to work like i want it to.

You will have to do more than just do a query.

  1. Do a data-query (or even doing several queries) → regarding using → promiseAll()
  2. Also you will have to find unique → Categories, you will need this to know how much different Items will be showed inside REPEATER later

Let us say you have 3 different CATEGORY-TYPES?

But do we have really just 3-different CATEGORY-TYPES?
What about the COMPLEXES, which includes two different types of CATEGORIES → does it mean we have here a NEW (4-th) CATEGORY? → Winery&Farm, or do you want to split these COMPLEX-BUILDING (including both types of category) into two different categories. → So at the end in both of categories, this Building-complex can be found?

Did you make some thoughts about this OPTION ?
How do you want to handle this?

I would take the REPEATER! And the code for it would be something like the following one…

   $w('#myRepeaterIDhere').data = itemData;

   $w('#myRepeaterIDhere').onItemReady(($item, itemData, index)=>{
      console.log("Items: ", itemData);
      console.log("Index: index);
      $item('#myRepeaterInternElementIDhere').text ="hereTheCountOfUniqueCategories"
   //continue here............

You are lucky, because i just today provided a code which could help you out…
Take a look at this post here…

If you take a very very intensive and close look at the given CODE, provided in the shown post, you will even find a lot of parts which you can use for your own purposes (including the —> unique-items) !

Good luck!