Calvin Cox
Posts: 0
Joined: Wed Nov 06, 2013 7:46 pm

Need help with JS to run a query based on 6 select components and displaying results on another page

Hi , I'm very confused and need some help:

I have a page with 6 select components. Each component will be selected by the user. After the user selects an option from each component they will click on a submit button that will query the database based on the values of the select components.

I've created local storage variables for the 6 select components and binded them to each component respectively.

I've created a database service to run a query from the page. I need help with the JS code that needs to be placed in the request setting for the "where" parameter.

I then need to display the query results on another page.

The query will search 6 columns based on the 6 select components looking for a match for each user input. There are 2 possibilities where the query will return a True value 1) when the user input matches that of the database column or when the database column string is "all" this will repeat for all 6 columns.

This the user input matches all 6 columns then the results will be displayed.

If the above is false then the query will not select that row for display and move to the next row to evaluate the query.

Once the query is complete I need to display the results on another page and I'm not sure how to do that either.

I've been trying to read and understand the other post in the forum but haven't been successful in figuring out how to implement it in my program.

Please help!

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Need help with JS to run a query based on 6 select components and displaying results on another page

Hello,

  1. You should check if your service return correct response when you test it:
    http://docs.appery.io/tutorials/build...

    2.Doc how to make DB queries:
    http://docs.appery.io/documentation/r...

  2. Using a REST service on a page: http://docs.appery.io/documentation/u...

  3. Query Constraints : http://docs.appery.io/documentation/b...

    If this references will not help you can share your app with a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a and we will help you to resolve your issue.

Calvin Cox
Posts: 0
Joined: Wed Nov 06, 2013 7:46 pm

Need help with JS to run a query based on 6 select components and displaying results on another page

Hi Igor,

I'm sorry but the reason I posted this question here is because I've read all the documents you've referenced and still can't figure out what to do to solve my problem. Can you help me figure out the js code needed to fix my problem?

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Need help with JS to run a query based on 6 select components and displaying results on another page

Yes, we can help. Please share your app with a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a and tell us app name.

Calvin Cox
Posts: 0
Joined: Wed Nov 06, 2013 7:46 pm

Need help with JS to run a query based on 6 select components and displaying results on another page

I've tried to contact support to help me solve this problem and no one has gotten back to me: I've clarified what my problems and needs are below: I could really use some help here:

I have a page (Student_Info) with 7 select components. Each component will be selected by the user. After the user selects an option from each component they will click on the "find scholarships" button that will query the database based on the values of the select components.

I've created local storage variables for the 7 select components and binded them to each component respectively.

I've created a database service to run a query from the Student_Info page. I need help with the JS code that needs to be placed in the request setting for the "where" parameter on this page.

I then need to display the query results on scholarship_details page.

The query will search the 7 columns in the database that corresponds to the user input from the 7 select components. The scholarships in the database have certain eligibility criteria that must be met, therefore I need to compare those criteria with that of the user and if the user meets those criteria for that scholarship then the scholarship should be shown. There are 2 possibilities where the query will return a True value 1- when the user input matches each of the scholarship's criteria either by exact match or the scholarship criteria has an "all" string. this will repeat for all 7 criteria columns

(scholarship criteria columns in the database includes: s_grade, s_race, s_location, s_gpa, s_other, s_gender, s_major)

.

If the above is false then the query will not select that scholarship for display and move to the next scholarship row to evaluate the query.

Once the query is complete I need to display the results on scholarship details page and I'm not sure how to do that either.

I've been trying to read and understand the other post in the forum but haven't been successful in figuring out how to implement it in my program.

Please help!

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Need help with JS to run a query based on 6 select components and displaying results on another page

Hi Calvin,

We emailed you. I duplicate the answer. Let's continue here.

  1. [quote:]Once the query is complete I need to display the results on scholarship details page[/quote]Don't execute the request on this page. Make it right on the page 'scolarship details'. All the parameters are already saved in localStorage - so it won't be a problem.

  2. Add JS in mapping with parameter 'where'. In this JS check the value of the localStorage variables. If the value equals 'all', then don't include this parameter in 'where'.

    Please check and try. If it won't work - send us your code example. We'll help.

Calvin Cox
Posts: 0
Joined: Wed Nov 06, 2013 7:46 pm

Need help with JS to run a query based on 6 select components and displaying results on another page

[quote:]

  1. Add JS in mapping with parameter 'where'. In this JS check the value of the localStorege variables. If the value is equals 'all', then don't include this parameter in 'where'.
    [/quote]

    Hi,

    I added the code in the mapping for the scholarship details page (my results page) as outlined above but was not able to figure out the "OR" syntax to get it to work.

    right now the code is only providing results if all the user fields are equal to the criteria in the database but ignores everything else.

    Please help me figure out the "OR" logic for the below code:

    I need it to say: "s_gender":localStorage.getItem("u_gender") OR /b and so on...

    var whereClause = { "s_gender": localStorage.getItem("u_gender"),
    "s_location": localStorage.getItem("u_location"),
    "s_race": localStorage.getItem("u_race"),
    "s_grade": localStorage.getItem("u_grade"),
    "s_gpa": localStorage.getItem("u_gpa"),
    "s_major": localStorage.getItem("u_major"),
    "s_other": localStorage.getItem("u_other") };

    return JSON.stringify(whereClause);

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Need help with JS to run a query based on 6 select components and displaying results on another page

Hi Calvin,

The following query returns all the records where value of field 'my' equals 1 or 2:pre{"$or":[{"my":"1"}, {"my":"2"}]}/pre

Calvin Cox
Posts: 0
Joined: Wed Nov 06, 2013 7:46 pm

Need help with JS to run a query based on 6 select components and displaying results on another page

Thanks Katya,

That worked for one of the columns, but when I tried to query all columns it errors out. See code and screen shot below: Please help.

var whereClause = {{"$or":[{"s_gender":localStorage.getItem("u_gender")}, {"s_gender":"all"}]},
{"$or":[{"s_location":localStorage.getItem("u_location")}, {"s_location":"all"}]},
{"$or":[{"s_major":localStorage.getItem("u_major")}, {"s_major":"all"}]},
{"$or":[{"s_race":localStorage.getItem("u_race")}, {"s_race":"all"}]},
{"$or":[{"s_grade":localStorage.getItem("u_grade")}, {"s_grade":"all"}]},
{"$or":[{"s_gpa":localStorage.getItem("u_gpa")}, {"s_gpa":"all"}]},
{"$or":[{"s_other":localStorage.getItem("u_other")}, {"s_other":"all"}]}

};

return JSON.stringify(whereClause);

Image

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Need help with JS to run a query based on 6 select components and displaying results on another page

Calvin,

The above code unites on "and" the results of all "and", right?
Here is the example of logic, which is now (if not correct me please):pre(s_location = u_location) or (s_location == all)
and
...
and
(s_other = u_other) or (s_other == all)/pre

Return to “Issues”