Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 0    Views: 104

PaddyO
Lost but trying
Profile
Posts: 189
Reg: Sep 11, 2013
Geelong
5,190
04/29/14 07:53 PM (10 years ago)

Trying to use an internally defined variable as part of an NSURL request

Hi all, For me this is about map data but it could be about any request to an external URL. Please bear with me... :) OK, I know we can send URLs that include specs and/or variables to request data from a database, eg http://www.mysite.com/some_script.php&deviceLatitude=38.44423&deviceLongitude=-103.48848" or http://www/mysite.com/another_script.php?someID=</a>'.$db_field["id"].' All good. Now it gets interesting. Let's say we want to allow a similar php/mySQL search based on some user input - let's say someone wants to search (our database) for 'armadillo' - and then we use that search term as the basis for a query that returns a different set of results from our database? What I've done: I have created a UITextField that takes user input (eg 'armadillo'), then I have defined that user-entered text as a variable, "userQuery". [My "- (BOOL)textFieldShouldReturn:(UITextField *)textField" method prints userQuery to NSLog and the log says that the value of userQuery is 'armadillo', so I know the definition has worked.] What I now want to do is to take userQuery (containing armadillo, or whatever the user-provided search term is at the time) and embed it in an NSURL request, something like this: NSURLRequest *searchString = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://mysite.com/user_request.php?searchterm=userQuery"]]; NSURLConnection *beamMeUp = [[NSURLConnection alloc] initWithRequest:searchString delegate:self]; But I know that the ?searchterm=userQuery bit is wonky. And it's not just the syntax... I'm thinking that even if userQuery formed part of the URL to the php file, the php script will somehow need to 'decode' userQuery and 'convert' it back to 'armadillo' so it can run the mySQL query with it. But only my app knows how to decode userQuery, the php script doesn't! And I can't hard-code 'armadillo' into the NSURL request, because that's just the search term of the moment. My head hurts! If anyone could shed some light or point some pointers that would be awesome. Thanks! Cheers Paddy
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.