Querying a Dataset on multiple pages

So were using Wix as a DB For our current busses, which are on time which are delayed ETC, now when one changes i want to update a text box at the top stating which ones are in an abnormal state, but i also want to make a push to the home page to show some visual indicator that this has occured as well, Is there a way for this to occur?

Hi Travis,

I guess you want to update a text box & show in home page when busses get a abnormal status?

1 Like

Yes, So i have the data set for the bussing table so when someone makes a change to the status field that it would to a HTML set for the text element we have selected.

Do you need the data become real time?

Well ideally 2 one on the bussing schedule page, and one on the home page for a little icon at the top

You can try to use setInterval to sort Last update & status in DB and change the text box every second.
It may create a real time action when someone change the busses status.

Hope it can be an idea for you.

Thanks that gives me a great idea, How ever how would i be able to query for which bus status` have changed?

theres the ondatachage event, but then iwant to execute a query for which status changed from running

Hi Travis,
When you update the status of busses, the Last update might also update. You can sort the newest of Last update and pass result to text box.

If there are two or more element will affect the field of Last Update, you can create one more field in DB to get the update time of busses status change. Therefore, you can sorting the newest update time and pass result to text box you need.

About sorting,

Good luck,

So i have generated a public.js file
contents of said file
import wixData from ‘wix-data’;
export function problems (){
var routeproblems = “”;
wixData.query(“database”)
.ne(“Status”, “Running”)
.find()
.then( (results) => {
var i = 0 ;
do {
routeproblems = routeproblems + " " + results.Route[i];
i++;
}
while (i <= results.length);
});
return routeproblems;
}
So basically we have a database for bussing , If the status changes to anything but running i need to report it back to the site, So i wrote this in my new-file.js
on the dynamic page, i have
import {problems} from ‘public/new-file.js’ ;
export function table1_click(event, $w) {
//Add your code for this event here:
var pb = problems();
if (pb !== “”){
$w(“#text18”).html = “The Following Bussing routes have problems” + pb;
$w(“#text14”).collapse();
$w(“#text17”).expand();
}
if (pb === “”){
$w(“#text18”).html = “All Busses are running as scheduled”;
$w(“#text17”).collapse();
$w(“#text14”).expand();
}
}
Where text 17/14 are text that i have formatted to be something specific for if there is a problem or not, But when i click on the table. no matter what is set in my status table i get "All busses are running as scheduled.
Any thoughts? currently i am just getting it to do it one one page then ill try it on multiple.

Hi Travis,

Um, do you want to create a button and use it as a trigger to filter or sort busses ?
In your code, it sims to do the function above.

Another question is that are there any trigger for busses status change between running and not running ?

Actually that’s what this is suppose to do is for every bus not with the Running word in the status field
Grab the route field contents join them together to display them in a text box.

Hi Travis,

I suggest you to use table or repeater to do the function, since they can let the code fewer.

You can add a table or repeater to your page and add a button to do a sorting action.

export function bussesSortingButton_click() {
var notRunning;
wixData.query(“BussesDatabase”).eq(“bussesStats”, notRunning ).find().then((res)=> {
If (res.items.length > 0) {
$w(“#table”).rows = res.items;
$w(“#table”).expand;
$w(“#itemNotMatchText”).collapse;
} else {
$w(“#itemsNotMatchText”).expand;
$w(“#table”).collapse();
}
});
}

Im not trying to create a sort for the front page, i want to search (query) on the back end for anything not running so we can let parents know to look for their bus as there are problems with it. and then load it on every page as we have a designated icon and text that will change alerting parents to bussing problems.