Fetching data from database using user Id

Hello there,
I have a database “attendance”


and I want to display the data in a page of a particular user based on there ID, that is one needs to enter his/her to display his/her data from database. can anyone explain me how can I do it???

You can do a query like this:

import wixData from 'wix-data';

let userId = < id of user >
wixData.query("attendance")
  .eq("_id", userId)
  .find()
  .then( (results) => {
    if(results.items.length > 0) {
      let items = results.items;
      let item = items[0];
      $w("#name").text = item.name;
      $w("#sub1").text = item.sub1;
      ... set all of your other fields ...
    } else {
      // handle case where no matching items found
    }
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

You might want to set up a table of all of the users, and then when you click on a user it goes to a dynamic page displaying all of their information. Use the Table Index example to see how that’s done.

Thanks for replying, may god bless you! I want to discuss this thing with you in deep! Can I you tell me where should I contact you?

Contact is in the forum. This way other users can learn and even contribute their experiences.

I would suggest playing with the Table Index example. You can then start building your own site that retrieves user information.

@yisrael-wix I am not good at coding! but I need a online attendance system! can you please explain me how to do it

This what error I am getting please help me out

@uditkumarswaroopa091

You will need to complete the code based on your needs. The error you are getting is on a “placeholder” that I used to indicate what you need to do the query.

We appreciate your interest in getting the most out of Wix Code and how much you want to learn. You will need to familiarize yourself with basic coding concepts to accomplish what you want. There are a wealth of Javascript coding sites which will help you learn Javascript from basic to advanced.

I would suggest visiting the following sites for information on programming in Javascript and Wix Code:

You may also want to check out the WixArena - it’s a hub where you can look for Wix Code (and other) experts for hire.

No, I know about basic coding! I just can’t figure out this part. Can you please help me to figure it out please

We are unable to provide full code solutions. You can take advantage of the Wix Code Resources including a good number of examples which demonstrate many of the techniques that you need to accomplish your goal. Here are the locations of the examples:

The code snippet that I posted above shows exactly how to perform a query based on the a user ID. You can get the user ID from an input field on the screen:

let userId = $w("#input").value;

Once you have the userId, you can then perform the query to get the user’s data.

Good luck

@jeff-haskins It’s not possible to add a filter from the dataset’s Settings window, but you should be able to filter by ID (_id) in code.

Thanks a lot @Yisrael I have learned a java script a bit and then did what you told me to do thanks a lot!

Is your problem solved?