Feedback from users

Is possible to add a database with different items with number of likes?
I’ll explain better: I have different items and i want some feedback by my users, like “likes” on facebook. Maybe it can be done by adding a button on my item page, and when a user clicks on it a signal is launched to my database, and increase the number of likes for that item by 1.
I tried to create a new database where people info can be written, with a column set to “number”, but i don’t know how to set a button for each product from the “products” database in my dynamic pages. I think that i need a code to combine this things, something like “let likes=n, n=0, when people clicks the like button set the n=n+1”
Thanks!

Wouldn´t it just be enough to add a field to your product collection called “Numner of likes” and increment that number when someone clicks “Like”’

Yeah for sure Giri, but to add that field is easy, just put a text on the dynamic page and connect it to the like’s column of the database

Hi!

So i’m not sure i got, what is the problem here? You for sure can create a button on dyn page, set up a onClick event handler and:

  1. get current item from dyn page dataset
  2. Get number of likes which is field in collection
  3. Increment it by 1
  4. Save back with same id (of the found item)

This is achieveable with https://www.wix.com/code/reference/wix-data.html module…

Yeah I’m trying to do that :slight_smile: This is what i got:

import wixData from ‘wix-data’;

function get(collectinName: Products, itemId: \my item id);
function get(collectinName: Products, likes);

export function LikeButton_click(event, $w) {
likes=likes+1;
}

Now, that is surely wrong haha. Can someone help me, please? Thanks!

Hello,

Assuming the following:

  1. Your dataset id is “dynamicDataset”.
  2. You have added column to the collection with type Number and name “likes”.
  3. You have added the “LikeButton_click” handler function as you described above.

The following code should achieve your goal:

export function button1_click(event, $w) {
	// read the current number of likes from the displayed record
	const currentNumberOfLikes = $w("#dynamicDataset").getCurrentItem().likes || 0;
	// increment likes by +1
	$w("#dynamicDataset").setFieldValue('likes', currentNumberOfLikes + 1);
	// save the updated record to the database
	$w("#dynamicDataset").save();
}

Also, please note that in order for you to be able to keep the new value to the database, you will need to set the dataset to “Read & Write” via the dataset’s settings panel.

Good luck!

Hi good day!

May I insert my self here?
How can I filter my database by owner ID (_owner) and display it into the repeater?

$w.onReady(() => {

	wixData.query("regdog")
		.eq("_owner")
		.find()
		.then((results) => {

			$w('#repeater1').data = results.items;

		})

	.catch((err) => {
		console.log(err);
	});
});

The code above is not working probably. I hope someone can help me in this.

Thank you,
Geo

1 Like

Hey Geo,
You’re missing the value which the _owner field should equal to.
.eq(“_owner”)
should become
.eq(“_owner”, ID_OF_THE_RELEVANT_OWNER)

1 Like

Hi Dor,

Good day!
I hope you can help me with this simple problem of mine. How can I get this kind of image URL? see image below

1 Like