Question

FMDatabase *database = [FMDatabase databaseWithPath:databasePath]; [database open];

FMResultSet *results = nil;
results=[database executeQuery:@"SELECT * FROM CLINIQDB"];

while([results next])
{
    countryArr=[[NSMutableArray alloc] init];

    [countryArr addObject:[results stringForColumn:@"countryNames"]];

}

    NSLog(@"The country arr %@",countryArr);
[database close];

Actually I have 10 country names but contryArr showing only last value for example my countries are {India,Australia,..........,Russia};

countryArr have only Russia in it.

what's wrong with my code.

Was it helpful?

Solution

Initialise your array before of while loop

FMResultSet *results = nil;
results=[database executeQuery:@"SELECT * FROM CLINIQDB"];

countryArr=[[NSMutableArray alloc] init];

while([results next])
{

    [countryArr addObject:[results stringForColumn:@"countryNames"]];

}

NSLog(@"The country arr %@",countryArr);
[database close];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top