Note that there are some explanatory texts on larger screens.

plurals
  1. POFMDB Result of table to JSON object respecting the order of the columns.
    primarykey
    data
    text
    <p>EDIT: NEW QUESTION AT BOTTOM It was getting all the rows I was wrong I am trying to get the results of an SQL query and place them into a json object to send to my server to do more work with the data. Right now my code is only returning 1 row of data. Can anyone see any glaring mistakes? IOS SIDE </p> <pre><code>- (void)sendLogin { NSError *jsonError; NSData *requestdata; //get login NSArray *docPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDir = [docPaths objectAtIndex:0]; NSString *dbPath = [documentsDir stringByAppendingPathComponent:@"tar.sqlite"]; FMDatabase *database = [FMDatabase databaseWithPath:dbPath]; [database open]; FMResultSet *Loginresults = [database executeQuery:@"SELECT * FROM surveys"]; NSMutableArray *results = [NSMutableArray array]; while ([Loginresults next]) { [results addObject:[Loginresults resultDictionary]]; requestdata = [NSJSONSerialization dataWithJSONObject:results options:0 error:&amp;jsonError]; } [database close]; NSURL *url = [NSURL URLWithString:@"http://server/insert.php"]; NSMutableURLRequest *request; request = [NSMutableURLRequest requestWithURL:url]; [request setHTTPMethod:@"POST"]; [request setValue:[NSString stringWithFormat:@"%d", [requestdata length]] forHTTPHeaderField:@"Content-Length"]; [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:requestdata]; //this kicks off the request asynchronously NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; } </code></pre> <p>PHP SIDE</p> <pre><code>&lt;?php $foo = file_get_contents("php://input"); var_dump(json_decode($foo, true)); ?&gt; </code></pre> <p>Results from this </p> <pre><code>finish requesting: array(1) { [0]=&gt; array(7) { ["desc"]=&gt; string(13) "matt the best" ["creator"]=&gt; string(7) "eric jr" ["synch"]=&gt; NULL ["name"]=&gt; string(4) "matt" ["sid"]=&gt; string(1) "1" ["datetime"]=&gt; string(3) "now" ["pid"]=&gt; string(1) "1" } } </code></pre> <p>Also I noticed my results for that table are not in the correct order. Is that working as intended? Is there any way to order this so it matches the order of the columns?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload