Setting Up Database to be Searched

I’ve looked through the forum, read countless threads and watched videos, and now have a semi-solid grasp of how the databases work. I’ve been playing with my site, but need some specific direction. My coding skills are limited, so I don’t want to create something that I will have a disaster of a time troubleshooting if something goes awry when it’s live.

My goal is to have service providers submit a portfolio (list of services, small details of service, pictures of services) and then to have visitors be able to search the results by their service type, the small details of service and to be able to sort the results. For example, a baker clicks off checkboxes indicating that they make cupcakes, wedding cakes and birthday cakes. The baker uses a dropdown to indicate that they make custom designs (yes or no). The baker also submits three photos and provides a price list. Then, visitors can hopefully click off boxes displaying all of the service providers who provide the desired service, and can narrow down those results based on other options. They could also filter those results in a few ways (distance, price, etc).

I’ve set up a database with the desired fields and created the portfolio submission page linked to the appropriate fields. As it’s currently setup, the bakers click off boxes for the services that they provide, which uses boolean values. When I try to create a search for the results, I can’t seem to find a way to display boolean data.

  1. How can I search results using bolean values?
  2. How do I set up a “sort” feature of the results?

Thanks!

Hi,

You can search using the checkbox isChecked property right against the appropriate field. A query might look something like this:

wixData.query("myCollection")
  .eq("myService", $w("#myCheckbox").checked;)
  .find()
  .then( (results) => {
    let items = results.items;
    // do stuff with items
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

For sorting, you can append either ascending or descending conditions. There are many other options available which will let you create just about any query that you want.

Have fun,

Yisrael

Thanks for your reply! I think I am starting to get it.

  1. Would I then repeat this for each individual checkbox?
  2. What would I put for “do stuff with items” spot? I am displaying the results in a repeater, not a table.

1 . Instead of repeating for every checkbox, put it in a function that’s called from each checkbox event handler. This keeps the code easier to read and maintain.

2 . You can use items to set the data properly of the Repeater:
$w(“#myRepeater”).data = results.items;
Since you’re using a repeater, you will of course need to have an onReady() function. But you knew that already - right?

Good luck and have fun,

Yisrael

Hello again! I’ve been playing for a bit, and still slowly starting to understand this more and more. I keep going over other posts and more videos to try and refine my code with my limited knowledge. Hold back your laughter when you look at the code I’m about to post. Please let me know what I’m doing wrong! Again, I am trying to display results in a repeater based on whether items are checked off or not. I would like for the repeater to be hidden on load, and then all items related to the checked off box (or multiple boxes) to appear!

import wixData from ‘wix-data’;

function fillRepeater() {
wixData.query(“Artists”)
.eq(“cupcakes”, $w(“#checkbox1”).checked);
wixData.query(“Artists”)
.eq(“bridalCakes”, $w(“#checkbox2”).checked);
wixData.query(“Artists”)
.eq(“dessertBars”, $w(“#checkbox3”).checked);
wixData.query(“Artists”)
.eq(“sheetCakes”, $w(“#checkbox4”).checked);
.find()
.then((results) => {
//console.log(results.items);
let services = results.items;
//console.log(services.length);
$w(‘#repeater1’).data = services; // fills the repeater
});
})
.catch((err) => {
let errorMsg = err;
console.log(errorMsg);
});
}
$w.onReady(function() {
fillRepeater();
$w(‘#repeater1’).onItemReady(($w, itemData) => {
$w(‘#text51’).text = itemData.services;
$w(‘#text50’).text = itemData.travel ? ;
$w(‘#text49’).text = itemData.travelfee;
$w(‘#image1’).src = itemData.portfolio1;
});
});
export function checkbox_changed(event, $w) {
fillRepeater();
}

Hi,

Unfortunately your code has many syntax and logic errors. We are unable to provide code solutions on the forum.

You will need to familiarize yourself with basic coding concepts to accomplish what you want. I would suggest starting with the Wix Code Basics and working your way through the other topis. Playing with the Examples in the editor will give your valuable “hands-on” experience. The Wix Code Resources page provides tutorials, examples, and articles on getting the most out of Wix Code. We are happy to get you pointed in the right direction, but you’ll need to take it from there. As questions or difficulties arise, we are here to help.

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.

Good luck and have fun,

Yisrael