Dennis Nygaard Nielsen
Posts: 0
Joined: Fri May 01, 2015 9:34 pm

How can I use value from input field as basis for a query?

Hi.
I have made a map from a input field to my database. Name of the input field is lMin. Whatever input I have here should make a query in the database. For now this looks like:

return '{"$and": [{"filter_high":{"$lte": "'+value+'"}},{"filter_low": {"$gte": "'+value+'"}}]}';

Only problem is that nothing shows up. If I put in the data from the database instead of the +value+, everything works fine. Can anyone see what I am doing wrong?

Thank you so much

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

How can I use value from input field as basis for a query?

Dennis,

Is the collection field numeric or string type?

Best,
Bruce

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

How can I use value from input field as basis for a query?

Dennis,

On further thought before you return the query using your return statement ... Log it to the console...

So...

var sreturn = ....your code
console.log ( sreturn );
return sreturn

Scape the code from the console... Into your service and test it there.... And tweak it till it works... And then adjust your code accordingly...

Best,
Bruce

Dennis Nygaard Nielsen
Posts: 0
Joined: Fri May 01, 2015 9:34 pm

How can I use value from input field as basis for a query?

It doesn't really work for me :/ I have attached some pictures to show what I want:

Image Image Image

Dennis Nygaard Nielsen
Posts: 0
Joined: Fri May 01, 2015 9:34 pm

How can I use value from input field as basis for a query?

Allright, the alert here is showing the proper data. Now I would like to get this data into my query, what am i doing wrong here?

var input = Apperyio('lMin');
alert (input.text());

return '{"$and": [{"filter_high":{"$lte": input.text() }},{"filter_low": {"$gte": input.text() }}]}';

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

How can I use value from input field as basis for a query?

Hi Dennis,

A couple of things that might help.

  1. Understanding the value of the where clause that you are sending to the service is of the highest importance. If you are going to 'alert' something - the best thing to pop up at this juncture - would be your return value - literally this value:

    var spopup = '{"$and": [{"filter_high":{"$lte": input.text() }},{"filter_low": {"$gte": input.text() }}]}';
    alert( spopup) ;

    If you're unsure on how to use the debugger - two items.

  2. Use Chrome - it has the best debugging tools.

  3. If you're unsure on how to use the console & the debugger to debug this problem - read this article:

    https://devcenter.appery.io/documenta...

  4. Specifically related to your challenge - since the field is numeric - you won't put quotes around it.... here's my take at your best query - not knowing more...

    var sreturn = '{"$and": [{"filter_high":{"$lte":' + input.text() + ' }},{"filter_low": {"$gte":' + input.text() + ' }}]}';
    console.log( sreturn);
    alert( sreturn);
    return sreturn;

  5. If that doesn't work - learn how to take the value that got logged to your console - (when the 2nd statement executes above) - and copy and paste it into the service tester.

    https://devcenter.appery.io/documenta...

    let me know what comes back - and good luck!

    Bruce

Dennis Nygaard Nielsen
Posts: 0
Joined: Fri May 01, 2015 9:34 pm

How can I use value from input field as basis for a query?

This here worked:
var input = Apperyio('lMin');

var sreturn = '{"$and": [{"filter_high":{"$lte":' + input.text() + ' }},{"filter_low": {"$gte":' + input.text() + ' }}]}';
console.log( sreturn);
return sreturn;

Thank you so much Bruce!

One more question, where would I add "ORDER BY catno" to this?
I am reproducing an old app I made 5 years ago in clean JS with an Sqlite database, and having some trouble implementing things into Appery. So really appreciate your help.

My old line was:

Code: Select all

var rows = db.execute('SELECT DISTINCT category FROM products WHERE filter_low = ? ORDER BY catno', lmin, lmin ); 

btw. the alert part was just because I did not know about the build in console in chrome :)

Dennis Nygaard Nielsen
Posts: 0
Joined: Fri May 01, 2015 9:34 pm

How can I use value from input field as basis for a query?

Hi again... Hopefully last question for now. How can I pass the data from the list? When clicking "windy" I would like to show the DB "name" field. And when clicking name, I would like a new blank page to show up. How am i managing this?

Really surprised how many functions this site has compared to Appcelerator Titanium. Image

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

How can I use value from input field as basis for a query?

As it relates to order - you specify it in your service ---- like this....

Image

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

How can I use value from input field as basis for a query?

and then - when you execute your code - you map a value to it in the mapper - either by drag and drop, by putting a value in the "JS" or by some combination of both.

Return to “Issues”