ios - Send data to php file and pull stuff from data base based on that data not working objective c -


in application, user has ability post , others can comment on it. anyway, view post see title of on tableview pushes detail view. segue carries post id. display comments, must send post id php file. pull data database based on post id , echo in json array objective c can read , display it. problem never echoing data because either post id not getting transferred php file or else happening.

i use same objective c code below in other files send , insert data database , works fine not sure problem is.

here objective c:

-(void) getdata:(nsdata *) data{  nserror *error;  json = [nsjsonserialization jsonobjectwithdata:data options:kniloptions error:&error];  }    -(void) start{  nsmutablestring *poststring = [nsmutablestring stringwithstring:krecieveurl];  [poststring appendstring:[nsstring stringwithformat:@"?%@=%@", kid, _post_id]];  [poststring setstring:[poststring stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]];  nsmutableurlrequest *request = [[nsmutableurlrequest alloc] initwithurl:[nsurl urlwithstring:poststring]]; [request sethttpmethod:@"post"];  postconnection = [[nsurlconnection alloc] initwithrequest:request delegate:self startimmediately:yes];    nsurl *url = [nsurl urlwithstring:krecieveurl];  nsdata *data = [nsdata datawithcontentsofurl:url];  [self getdata:data];  } 

and php:

<?php   $db_connect = mysql_connect("localhost", "root", "")  or die("our servers down @ moment"); mysql_select_db("my db") or die("couldnt find db");   $post_id = $_get['id'];  $query = "select * comments post_id='$post_id'";  $results = mysql_query($query);  $num = mysql_numrows($results);  mysql_close();  $rows = array(); while($r = mysql_fetch_assoc($results)) { $rows[] = $r; }  echo json_encode($rows);     ?> 

try this

- (void)start {    nsmutablestring *poststring = [nsmutablestring stringwithstring:recieveurl];   [poststring appendstring:[nsstring stringwithformat:@"?%@=%@", kid, _post_id]];   [poststring setstring:[poststring stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]];   nsurlrequest *request = [[nsurlrequest alloc] initwithurl:[nsurl urlwithstring:poststring]];   [nsurlconnection sendasynchronousrequest:request                                      queue:[nsoperationqueue currentqueue]                          completionhandler:^(nsurlresponse *response, nsdata *data, nserror *error) {                            if (error) {                              // error handling                            } else {                              id json = [nsjsonserialization jsonobjectwithdata:data options:kniloptions error:&error];                              if (error) {                               // error handling                               } else {                                // json                              }                            }                          }]; } 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -