show and hide button according to field entered by user in database

Hello guys,
Currently I built a custom profile page and prompted the member to enter their data after that according to a specific field which is their profession I want to show a button or hide it

I know that first I have to retrieve their data from the database then write if statement to check what is their profession then write code to show certain button or hide it.
I need help on how I can retrieve data from the current logged in user and then read certain field.
Thanks in advance

Hi Mina ,

Regarding getting the current logged in user, you can achieve that with → wix-users#currentUser .
now you have the current user id, now lets query the id to retrieve his data, how? check this out - Query

Hope this helps!
Best,

Mustafa

thanks really, but what about the getitem() function can I use it to retrieve data and store it in a variable then I can process if statement according to the returned data?

@teachmekms Query will do that for you, You only declare what you want the query for, then you can use the result as you wish.

wixData.query("myCollection")
  .eq('_id')('userId')// userId: is the id you got from getCurrentUser
  .find()
  .then( (results) => {
    if(results.items.length > 0) {
      let firstItem = results.items[0]; 
      console.log(firstItem); // this will show you the data of the current user, that matched the query
    } else {
      // handle case where no matching items found
    }
  } )
  .catch( (err) => {
    let errorMsg = err;
  } );

@mhammouz thanks for your answers I really appreciate it :slight_smile: