[Solved] Table generated from databases. table flickers, sometimes doesn't load.

I am close to functional with this.
I set up databases for user to search based on a calculated value and return matching values based on a permutation scheme.

https://braphox.wixsite.com/website/copy-of-mobile-parts-lookup-1

I suspect the if - else if loop is triggering a null table.
Is it possible to stop the code once a match had been found to populate the table?

For the first bolded else if statement in the code below the table will load eventually if I click the button enough times. For the other two bolded else if lines nothing loads.

I have the databses all configured the same way and live.

Here are example numbers to try. the 1033 and 1053 have matches in their respective databases.

 **46**    268   314   366   438   457   508   559   586   608   679   709   746   750   798   823   866   890   920   970    **1033**    **1053**    1097   1132   1164   1223   1271   1307   1391   1455   1550   1602   1814   1917   2646     

Code below

// For full API documentation, including code examples, visit Velo API Reference - Wix.com
//TODO: write your code here…=RPGoal-CurrentRP
//export function switch1_click_1(event, $w)
//import {session} from ‘wix-storage’;
//session.setItem(“key”, “value”);

import wixData from ‘wix-data’;
$w.onReady( function () {

$w(“#table1”).columns = [{
“id”: “col1”, // ID of the column for code purposes
// The field key in the collection whose data this column displays
“dataPath”: “title”,
“label”: “Title”, // The column header
“width”: 100, // Column width
“visible”: false , // Column visibility
“type”: “string”, // Data type for the column
// Path for the column if it contains a link
//“linkPath”: “link-field-or-property”
},
{
“id”: “col2”, // ID of the column for code purposes
// The field key in the collection whose data this column displays
“dataPath”: “rpValue”,
“label”: “RP to earn”, // The column header
“width”: 100, // Column width
“visible”: true , // Column visibility
“type”: “Number”, // Data type for the column
// Path for the column if it contains a link
//“linkPath”: “link-field-or-property”
},
{
“id”: “col3”,
“dataPath”: “permutations”,
“label”: “# Parts Avail’”,
“width”: 100,
“visible”: true ,
“type”: “Number”,
//“linkPath”: “link-field-or-property”
} //,
// more column objects here if necessary
// …
// …
]

$w("#table2").columns = [{ 

“id”: “col1”, // ID of the column for code purposes
// The field key in the collection whose data this column displays
“dataPath”: “title”,
“label”: “Title”, // The column header
“width”: 100, // Column width
“visible”: false , // Column visibility
“type”: “string”, // Data type for the column
// Path for the column if it contains a link
//“linkPath”: “link-field-or-property”
},
{
“id”: “col2”, // ID of the column for code purposes
// The field key in the collection whose data this column displays
“dataPath”: “rp”,
“label”: “RP”, // The column header
“width”: 100, // Column width
“visible”: true , // Column visibility
“type”: “Number”, // Data type for the column
// Path for the column if it contains a link
//“linkPath”: “link-field-or-property”
},
{
“id”: “col3”,
“dataPath”: “part1”,
“label”: “Part 1’”,
“width”: 100,
“visible”: true ,
“type”: “text”,
//“linkPath”: “link-field-or-property”
} ,
{
“id”: “col4”,
“dataPath”: “part2”,
“label”: “Part 2’”,
“width”: 100,
“visible”: true ,
“type”: “text”,
//“linkPath”: “link-field-or-property”
} ,
{
“id”: “col5”,
“dataPath”: “part3”,
“label”: “Part 3’”,
“width”: 100,
“visible”: true ,
“type”: “text”,
//“linkPath”: “link-field-or-property”
} ,
{
“id”: “col6”,
“dataPath”: “part4”,
“label”: “Part 4’”,
“width”: 100,
“visible”: true ,
“type”: “text”,
//“linkPath”: “link-field-or-property”
} ,
{
“id”: “col7”,
“dataPath”: “part5”,
“label”: “Part 5’”,
“width”: 100,
“visible”: true ,
“type”: “text”,
//“linkPath”: “link-field-or-property”
} ,
{
“id”: “col7”,
“dataPath”: “part6”,
“label”: “Part 6’”,
“width”: 100,
“visible”: true ,
“type”: “text”,
//“linkPath”: “link-field-or-property”
} ,
{
“id”: “col7”,
“dataPath”: “part7”,
“label”: “Part 7’”,
“width”: 100,
“visible”: true ,
“type”: “text”,
//“linkPath”: “link-field-or-property”
} ,
// more column objects here if necessary
// …
// …
]

$w(“#button2”).hide();
});

export function button1_click_1(event, $w) {
$w(“#button1”).hide();
$w(“#button2”).show();
let toInsert = {

“begin”: $w(“#input1”).value ,
“end”: $w(“#input2”).value,
“difference”: $w(“#input2”).value-$w(“#input1”).value,

};
wixData.insert(“UserRP”, toInsert)
.then( (results) => {
let item = results;
} )
. catch ( (err) => {
let errorMsg = err;
})
}

export function button2_click(event, $w) {
//Add your code for this event here:
let diff = Number($w(“#input2”).value)-Number($w(“#input1”).value)
wixData.query(‘NumberOfPartslists’)
.eq(‘rpValue’,diff)
.find()
.then(res => {
$w(‘#table1’).rows = res.items;
$w(“#table1”).show();
});

//let rp = Number($w(“#input2”).value)-Number($w(“#input1”).value)
if (diff<=241) {
wixData.query(‘6_241RP’)

            .eq('rp',diff) 
            .find() 
            .then(res => { 
                $w('#table2').rows = res.items; 

// $w(“#table2”).show();
}) }
$w(“#table2”).refresh();
if (diff<=309) {
wixData.query(‘N242_309Parts’)

            .eq('rp',diff) 
            .find() 
            .then(res => { 
                $w('#table2').rows = res.items; 

// $w(“#table2”).show();
})}

if (diff===0) { wixData.query(‘Noparts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

//will populate table if button pressed enough times
else if (diff<=361) { wixData.query(‘B310_361Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=407) { wixData.query(‘B362_407Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=449) { wixData.query(‘B408_449Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=489) { wixData.query(‘450_489Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=529) { wixData.query(‘490_529Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=568) { wixData.query(‘530_568Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=606) { wixData.query(‘569_606Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=643) { wixData.query(‘B607_643Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=679) { wixData.query(‘644_679Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=713) { wixData.query(‘680_713Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=747) { wixData.query(‘714_747Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=780) { wixData.query(‘748_780Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=813) { wixData.query(‘B781_813Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=846) { wixData.query(‘814_846Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=879) { wixData.query(‘847_879Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=913) { wixData.query(‘B880_913Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=948) { wixData.query(‘914_948Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=985) { wixData.query(‘949_985Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

//nothing loads here
else if (diff <=1054) {wixData.query(‘dataset3’).eq(‘rp’,diff).find().then(res => { $w(‘table2’).rows=res.items;})}

//else if (diff<=1054) { wixData.query(‘A986_1054Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

//nothing load shere
else if (diff<=1065)
{ wixData.query(‘N1025_1065Parts’) .eq(‘rp’,diff)
.find()
.then(res => { $w(‘table2’).rows = res.items;})}

else if (diff<=1108) { wixData.query(‘1066_1108Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=1153) { wixData.query(‘1109_1153Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=1199) { wixData.query(‘A1154_1199Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=1248) { wixData.query(‘1200_1248Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=1300) { wixData.query(‘N1249_1300Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=1356) { wixData.query(‘1301_1356Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=1419) { wixData.query(‘A1357_1419Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=1492) { wixData.query(‘A1420_1492Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=1582) { wixData.query(‘B1493_1582Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=1692) { wixData.query(‘B1583_1692Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=1828) { wixData.query(‘B1693_1828Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=2050) { wixData.query(‘B1829_2050Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

else if (diff<=3780) { wixData.query(‘A2051_3780Parts’) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})}

//$w(“#table2”).show();

}

Logical operators are your friend.

Did a search if / else if to find the database name.
ex: else if (diff>= 949 && diff<=985) { var name = “949_985Parts”}
Forces an true statement for both conditions.

I still cannot get this database to populate the table. N1025_1065Parts

else if (diff>=1025 && diff <=1065) { var name = “N1025_1065Parts”} // doesnt workN
https://braphox.wixsite.com/website/copy-of-use-mobile-parts-lookup-1

If any admin with access. Could you please look. I have it synced, I have permissions set properly. I’ve even deleted the .csv and reuploaded a clean one. I’m out of ideas for the moment.

// For full API documentation, including code examples, visit Velo API Reference - Wix.com
//TODO: write your code here…=RPGoal-CurrentRP
//export function switch1_click_1(event, $w)
//import {session} from ‘wix-storage’;
//session.setItem(“key”, “value”);

import wixData from ‘wix-data’;
$w.onReady( function () {

$w(“#table1”).columns = [{
“id”: “col1”, // ID of the column for code purposes
// The field key in the collection whose data this column displays
“dataPath”: “title”,
“label”: “Title”, // The column header
“width”: 100, // Column width
“visible”: false , // Column visibility
“type”: “string”, // Data type for the column
// Path for the column if it contains a link
//“linkPath”: “link-field-or-property”
},
{
“id”: “col2”, // ID of the column for code purposes
// The field key in the collection whose data this column displays
“dataPath”: “rpValue”,
“label”: “RP to earn”, // The column header
“width”: 100, // Column width
“visible”: true , // Column visibility
“type”: “Number”, // Data type for the column
// Path for the column if it contains a link
//“linkPath”: “link-field-or-property”
},
{
“id”: “col3”,
“dataPath”: “permutations”,
“label”: “# Parts Avail’”,
“width”: 100,
“visible”: true ,
“type”: “Number”,
//“linkPath”: “link-field-or-property”
} //,
// more column objects here if necessary
// …
// …
]

$w("#table2").columns = [{ 

“id”: “col1”, // ID of the column for code purposes
// The field key in the collection whose data this column displays
“dataPath”: “title”,
“label”: “Title”, // The column header
“width”: 100, // Column width
“visible”: false , // Column visibility
“type”: “string”, // Data type for the column
// Path for the column if it contains a link
//“linkPath”: “link-field-or-property”
},
{
“id”: “col2”, // ID of the column for code purposes
// The field key in the collection whose data this column displays
“dataPath”: “rp”,
“label”: “RP”, // The column header
“width”: 100, // Column width
“visible”: true , // Column visibility
“type”: “Number”, // Data type for the column
// Path for the column if it contains a link
//“linkPath”: “link-field-or-property”
},
{
“id”: “col3”,
“dataPath”: “part1”,
“label”: “Part 1’”,
“width”: 100,
“visible”: true ,
“type”: “text”,
//“linkPath”: “link-field-or-property”
} ,
{
“id”: “col4”,
“dataPath”: “part2”,
“label”: “Part 2’”,
“width”: 100,
“visible”: true ,
“type”: “text”,
//“linkPath”: “link-field-or-property”
} ,
{
“id”: “col5”,
“dataPath”: “part3”,
“label”: “Part 3’”,
“width”: 100,
“visible”: true ,
“type”: “text”,
//“linkPath”: “link-field-or-property”
} ,
{
“id”: “col6”,
“dataPath”: “part4”,
“label”: “Part 4’”,
“width”: 100,
“visible”: true ,
“type”: “text”,
//“linkPath”: “link-field-or-property”
} ,
{
“id”: “col7”,
“dataPath”: “part5”,
“label”: “Part 5’”,
“width”: 100,
“visible”: true ,
“type”: “text”,
//“linkPath”: “link-field-or-property”
} ,
{
“id”: “col7”,
“dataPath”: “part6”,
“label”: “Part 6’”,
“width”: 100,
“visible”: true ,
“type”: “text”,
//“linkPath”: “link-field-or-property”
} ,
{
“id”: “col7”,
“dataPath”: “part7”,
“label”: “Part 7’”,
“width”: 100,
“visible”: true ,
“type”: “text”,
//“linkPath”: “link-field-or-property”
} ,
// more column objects here if necessary
// …
// …
]

$w(“#button2”).hide();
});

export function button1_click_1(event, $w) {
$w(“#button1”).hide();
$w(“#button2”).show();

let toInsert = {

“begin”: $w(“#input1”).value ,
“end”: $w(“#input2”).value,
“difference”: $w(“#input2”).value-$w(“#input1”).value,

//let diff = Number($w(“#input2”).value)-Number($w(“#input1”).value)

// wixData.query(‘NumberOfPartslists’).eq(‘rpValue’,diff).find().then(res => {$w(‘#table1’).rows = res.items;$w(“#table1”).show();});

//if (diff<=361) {var name=“B310_361Parts”}

};
wixData.insert(“UserRP”, toInsert)
.then( (results) => {
let item = results;
} )
. catch ( (err) => {
let errorMsg = err;
})
}

export function button2_click(event, $w) {
//Add your code for this event here:
let diff = Number($w(“#input2”).value)-Number($w(“#input1”).value)

        wixData.query('NumberOfPartslists').eq('rpValue',diff).find().then(res => {$w('#table1').rows = res.items;$w("#table1").show();}); 

//if (diff<=361) {var name=“B310_361Parts”}
if (diff>=6 && diff<=241) { var name=“6_241RP”}

else if (diff>=242 && diff<=309) { var name = “242_309Parts”}

else if (diff>=310 && diff<=361) { var name = “B310_361Parts”}

else if (diff>=362 && diff<=407) { var name = “B362_407Parts”}

else if (diff>=408 && diff<=449) { var name = “B408_449Parts”}

else if (diff>=450 && diff<=489) { var name = “450_489Parts”}

else if (diff>=490 && diff<=529) { var name = “490_529Parts”}

else if (diff>=530 && diff<=568) { var name = “530_568Parts”}

else if (diff>=569 && diff<=606) { var name = “569_606Parts”}

else if (diff>=607 && diff<=643) { var name = “B607_643Parts”}

else if (diff>=644 && diff<=679) { var name = “644_679Parts”}

else if (diff>=680 && diff<=713) { var name = “680_713Parts”}

else if (diff>=714 && diff<=747) { var name = “714_747Parts”}

else if (diff>=748 && diff<=780) { var name = “748_780Parts”}

else if (diff>=781 && diff<=813) { var name = “B781_813Parts”}

else if (diff>=814 && diff<=846) { var name = “814_846Parts”}

else if (diff>=847 && diff<=879) { var name = “847_879Parts”}

else if (diff>=880 && diff<=913) { var name = “B880_913Parts”}

else if (diff>=914 && diff<=948) { var name = “914_948Parts”}

else if (diff>= 949 && diff<=985) { var name = “949_985Parts”}

else if (diff>=986 && diff<=1054) { var name = “A986_1024Parts”} // doesnt work did once check again

else if (diff>=1025 && diff <=1065) { var name = “N1025_1065Parts”} // doesnt workN
else if (diff>=1066 && diff <=1108) { var name = “1066_1108Parts”}

else if (diff>=1109 && diff <=1153) { var name = “1109_1153Parts”}

else if (diff>=1154 && diff <=1199) { var name = “A1154_1199Parts”}

else if (diff>=1200 && diff <=1248) { var name = “1200_1248Parts”}

else if (diff>=1249 && diff <=1300) { var name = “N1249_1300Parts”}

else if (diff>= 1301 && diff <=1356) { var name = “1301_1356Parts”}

else if (diff>=1357 && diff<=1419) { var name = “A1357_1419Parts”}

else if (diff>= 1420 && diff <=1492) { var name = “A1420_1492Parts”}

else if (diff>= 1493 && diff <=1582) { var name = “B1493_1582Parts”}

else if (diff>= 1583 && diff <=1692) { var name = “B1583_1692Parts”}

else if (diff>= 1693 && diff <=1828) { var name = “B1693_1828Parts”}

else if (diff>=1829 && diff <=2050) { var name = “B1829_2050Parts”}

else if (diff>=2051 && diff <=3780) { var name = “A2051_3780Parts”}

console.log(name)

//$w(“#table2”).show();

wixData.query(name) .eq(‘rp’,diff).find().then(res => { $w(‘#table2’).rows = res.items;})

}

After a good nights rest I found the issue. An overlap in the && logical statement.
Before:
else if (diff>=986 && diff<=1054) { var name = “A986_1024Parts”} // doesnt work did once check again else if (diff>=1025 && diff <=1065) { var name = “N1025_1065Parts”} // doesnt workN

After:
else if (diff>=986 && diff<=1024) { var name = “A986_1024Parts”} // doesnt work did once check again else if (diff>=1025 && diff <=1065) { var name = “N1025_1065Parts”} // doesnt workN

I would like to thank everyone that helped with this.