Count number of time "Item" repeated in tinyDB

I am making a project for school. I’m having problem counting the total of transport student using to come to school. I have TAG=studentid with index 1=studentname index 2=address and index3=transport in tinydb. so i want to make a button counting the number of student using BUS to school from database in index3.

You will need your app to get ALL the tags and save that in a list, and then loop for all tags in that list to access the database, obtain each record, and for each of those record, access list index 3 and check for the value there. If it is BUS, you increment a counter (a global variable initially set to 0) by one.

When the loop ends, the counter would be set to the number of students reportedly riding the bus.

1 Like

Sorry I got an error. Or maybe there is some step I have done wrong. Have you help me to have a look on it… I think is the index problem.

blocks1 blocks2
This are the block I have.

When you call “Tiny_DB1.Get Tags”, what you should get then is a list that would include all the studentid.

Suppose, for the sake of argument that you have this:
TAG= std_01 ; record is (“Bill”, “12 Main”, “walks”)
TAG= std_02 ; record is (“Anita”, “33 Little road”, “Bus”)
TAG= std_03 ; record is (“Jane”, “74 Broadway”, “Bus”)

then calling “Tiny_DB1.Get Tags” returns (“std_01”, “std_02”, “std_03”)
So, already, your “for each item in list” will readily go through all of those, in that order.

You call Tiny_DB1. Get Value, and you will get list (“Bill”, “12 Main”, “walks”) for the first call.
You DO NOT try to Get Value using “walks” as a tag.
You instead should get element #3 of the LIST you should have gotten.

Skipping the intermediate steps, and therefore not making allowance in case one record does not have 3 elements (but still addressing the possibility that you’d get a tag for a record that does no exist), you could get


Notice the difference?
You get the list, THEN you can look for item #3

And I have no idea why you’d want to save the data in a local Database variable for. You already have the data in TinyDB, why do you need to make a second copy? Is that a requirement? Because if you have dozen of records, that is how many lines there will be in ListView1.