# How to Populate a Table Object with member-specific data from a query

**URL:** <https://forum.wixstudio.com/t/how-to-populate-a-table-object-with-member-specific-data-from-a-query/51430>\
**Category:** Ask the community\
**Tags:** design, code, wix-members-area\
**Created:** [August 12, 2023, 12:56am UTC](https://forum.wixstudio.com/t/how-to-populate-a-table-object-with-member-specific-data-from-a-query/51430 "2023-08-12T00:56:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rob\_Winona\_Hollis](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/rob_winona_hollis/32/81014_2.png) [@Rob\_Winona\_Hollis](https://forum.wixstudio.com/u/Rob_Winona_Hollis)\
**Post date:** [August 12, 2023, 12:56am UTC](https://forum.wixstudio.com/t/how-to-populate-a-table-object-with-member-specific-data-from-a-query/51430/1 "2023-08-12T00:56:51Z")

</div>

**My Challenge: On a Private Members page I need to display a table of information that’s specific to the logged-in member.** For example, a history of appointments. I asked Advance Support and received this response:

* * *

_I understand you would like to display content from a database collection but only allow users to see the items from the collection that are related to them. TO do this you need to add some code to your site using Velo by Wix._

_To do this, create a database collection with all the fields you need, as well as a reference field connected to the PrivateMembersData collection._

_On the page you want to display the data:_

_1. Use getMember() to get the ID of the current member._  
_2. Query() the collection and filter by the reference field using the ID._  
_3. Use the results of the query to display the data on the page._

## _Filtering the collection by the ID of the logged-in user will ensure they only see data linked with them._

So, I have created a Collection (“Appts”) with a Reference Field (“memberRef”).

On the Private Member Page I placed a Table object. (The available Repeaters would take _far_ more formatting time, and I have the Table layout and design done. I may want to use a Repeater for another application, but for now I want to solve the Table challenge.)

This is where I am…

// Loading Table Object direct from query results  
// This code is NOT the solution. See details in-line  
import wixData from ‘wix-data’;  
import wixUsers from ‘wix-users’;

const user = wixUsers.currentUser;  
const memberId = user.id;

$w.onReady(function () {

try {  
// Query the “Appointments” collection  
let wixDataQueryAppointments = wixData.query(‘Appts’)  
.eq(‘memberRef.memberId’, memberId) **← ISSUE #1**  
.find()  
.then((results) =\> {  
console.log("Member ID = " + memberId);  
console.log("Query Row Count = " + results.totalCount);  
console.log( results );

```
	  if ( results.totalCount > 0) {
		  $w('#appointmentsTable').show();
		  $w('#noAppointmentsMessage').hide();
		  $w('#appointmentsTable').rows = results.items; **<-- ISSUE #2**
		  console.log("DONE LOADING RESULTS!");
	  } else {
		  $w('#noAppointmentsMessage').show();
		  console.log("Invoking hide() on #appointmentsTable");
		  $w('#appointmentsTable').hide();
		}
  }).catch((err) => {
	  console.log("EGREGIOUS ERROR!");
	  console.log(err);
  });

```

} catch (error) {  
console.error(‘Error querying appointments:’, error);  
}  
});

**ISSUE #1:** Without this filter, I get a result set (but with all members, of course). Adding this .eq(), I get a 0-length result set. What would be the syntax for eq()'ing on the user.id?

**ISSUE #2:** When I remove the .eq(), I get a result set, but the table does not get populated. How do I get the results into the Table object for presentation to the user?

Thanks in advance. I’ve been stuck on this for days!

---

<div class="post-metadata">

**Author:** ![Rob\_Winona\_Hollis](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/rob_winona_hollis/32/81014_2.png) [@Rob\_Winona\_Hollis](https://forum.wixstudio.com/u/Rob_Winona_Hollis)\
**Post date:** [August 12, 2023, 7:13pm UTC](https://forum.wixstudio.com/t/how-to-populate-a-table-object-with-member-specific-data-from-a-query/51430/2 "2023-08-12T19:13:51Z")

</div>

For posterity, **Issue #1: SOLVED**  
This line of code had 2 errors.

First, when you add a Reference field to your Collection that joins to another Collection, you have to use the Wix-generated _ **Field key** _, but I was using the “Field name”. The “Field key” is _ **reference** _.

Second, _ **reference** _ is the Member ID. Discovered this by opening each ‘item’ in the Chrome console and seeing the values of the reference field. So, I did not have to piece together a path. This Line of Code simply became this:

.eq(‘reference’, memberId)
