Matching repeat region cell data to query

I have a repeat region that is displaying items from a database table. Let’s call them Tweets. In each cell, I would like to display the number of “likes” for each. The “likes” are obtained by searching a separate database table where the tweet id and user id are stored. I think I need to sum the number of user ids that match each cell’s tweet id and display that number but I’m not sure how I would go about doing that in Wappler.

After working on this a bit more, I’ve been able to get the server side part of it working by manually adding the lookup id to the query filter tab and using set value to do a count of the results. I can then bind this result in the repeat region, but it just repeats this static value for each cell.

What I need to do is somehow lookup each cell’s count. I have tried setting up a globals get variable and app connect with an input parameter set to the repeat region row’s id but I’m not getting anything. I also tried sending the repeat region row’s id to an array input parameter to connect with a server side globals get array but still nothing.

Hi @dserber
You can use the Aggregate functions available in the query builder and apply count to your filtered query. It will return the numbers of records returned:

1 Like

Thanks @Teodor!

Two issues:

  1. How do I get the data from the repeat region over to server connect to be used to filter in the query conditions tab?

Here’s what I have in the query:

Here’s my get globals (new_id):
49%20AM

And here’s the server connect which is setup to receive an input parameter that is coming from the repeat region row “recently_added”.

  1. How do I send it back to the correct repeat region’s cell so that I can bind it?

It just displays as [object object] across all the repeat region’s columns.

I am not sure I understand what are you doing exactly. Are you using two separate server actions for this (display records and display likes) and are you trying to filter a server action by a value repeated in a repeat region on the page?

Yes

That’s not the right approach. Please use a single server action with nested queries:

Apply the aggregate function to the nested one.

1 Like

I think I have it working on server connect.

image

How do I bind the aggregated value on the page? I tried selecting margin_id but it doesn’t display anything.

Sorry i forgot to mention that you will need to add an alias to be able to call the results on the page.
So, just add any alias name here:

And on the page you will see it available in the data picker:

1 Like

Thanks @Teodor! Worked perfectly!

1 Like