Вопрос

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.

Это было полезно?

Решение

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];
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top