Page 1 of 2
					
			
				How can I use value from input field as basis for a query?
				Posted: Fri May 01, 2015 9:34 pm
				by Dennis Nygaard Nielsen
				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
 
			 
					
			
				How can I use value from input field as basis for a query?
				Posted: Sat May 02, 2015 3:20 am
				by Bruce Stuart
				Dennis,
 
 Is the collection field numeric or string type?
  
 Best, 
 Bruce
 
			 
					
			
				How can I use value from input field as basis for a query?
				Posted: Sat May 02, 2015 3:25 am
				by Bruce Stuart
				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
 
			 
					
			
				How can I use value from input field as basis for a query?
				Posted: Sat May 02, 2015 8:26 am
				by Dennis Nygaard Nielsen
				It doesn't really work for me :/ I have attached some pictures to show what I want:
 
  
  
  
 
 
			 
					
			
				How can I use value from input field as basis for a query?
				Posted: Sat May 02, 2015 11:40 am
				by Dennis Nygaard Nielsen
				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() }}]}';
 
			 
					
			
				How can I use value from input field as basis for a query?
				Posted: Sat May 02, 2015 8:06 pm
				by Bruce Stuart
				Hi Dennis,
 
 A couple of things that might help.
  
 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.
  
 Use Chrome - it has the best debugging tools.
  
 If you're unsure on how to use the console & the debugger to debug this problem - read this article:
 
 https://devcenter.appery.io/documenta...
  
 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;
  
 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
 
			 
					
			
				How can I use value from input field as basis for a query?
				Posted: Sat May 02, 2015 10:17 pm
				by Dennis Nygaard Nielsen
				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 
 
			 
					
			
				How can I use value from input field as basis for a query?
				Posted: Sat May 02, 2015 10:42 pm
				by Dennis Nygaard Nielsen
				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. 
 
 
			 
					
			
				How can I use value from input field as basis for a query?
				Posted: Sun May 03, 2015 2:53 am
				by Bruce Stuart
				As it relates to order - you specify it in your service ---- like this....
 
  
 
 
			 
					
			
				How can I use value from input field as basis for a query?
				Posted: Sun May 03, 2015 2:54 am
				by Bruce Stuart
				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.