1 repeater, 2 datasets, trouble showing if an item has already been selected by user.

I have one repeater that contains a text box, image, and two vector icons for the user to click if they like the item or not. The data for the repeater is from dataset1 (list of books). When the user clicks one of the vector icons it inserts a 1 or -1 to dataset2 in the users row. Dataset2 is filtered for logged in user. In dataset2 the headings of the columns are the names of the books. I am learning how to code as I go and I can’t seem to figure out how to show if the user has already selected if they like the book or not when they open that page. don’t know if I need a loop or what.

Hi,
You need to save each vote in the database, that record needs to include the user’s ID, name of the book etc…
Then, to check for the user’s vote, you need to use query on the database and check if there are any record for a specific book from the current user, use this code as an example:

wixData.query("myCollection")
  .eq("book", "nameOfTheBook")
  .eq("user" , currentUser)
  .find()
  .then( (results) => {
    if(results.items.length >0){
      // user already submitted vote for the book
    }
  } )
  .catch( (err) => {
    let errorMsg = err;
  } );

Good luck :slight_smile: