Question

In my app, I have a database with values like name, number, mark.
I can recruit the values from the db as each array for name, number and mark.
I want to get the values of each person
Consider I have 3 students.

nameArray=(a,b,c);
numberArray=(1,2,3);
markArray=(25,50,75);

Now I want to get separate the value for each student, I needed

stud1=(a,1,25);
stud2=(b,2,50);
stud3=(c,3,75);

I couldnt get any idea for this, any help would be appreciated

Was it helpful?

Solution

OK, if you want to do a select statement that takes all the relevant data for a student, check out one or both of these guides. They're not the most current but the have what you need:

http://www.raywenderlich.com/913/sqlite-tutorial-for-ios-making-our-app

This example starts off with a FailedBankInfo object, which would match up with your Student. Note that they have the following method to create one of these objects using the values from the database:

- (id)initWithUniqueId:(int)uniqueId name:(NSString *)name city:(NSString *)city 
    state:(NSString *)state 

The tutorial shows you how to get those values and to loop through the results.

Here's a second tutorial:

http://dblog.com.au/iphone-development-tutorials/iphone-sdk-tutorial-reading-data-from-a-sqlite-database/

In this one, the example at the start is an Animal object. A number of Animals are created from values in the database, similar to your Student. The Animal class looks like this:

@interface Animal : NSObject {
    NSString *name;
    NSString *description;
    NSString *imageURL;
}

@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *description;
@property (nonatomic, retain) NSString *imageURL;

-(id)initWithName:(NSString *)n description:(NSString *)d url:(NSString *)u;

@end

Those tutorials should get you going.

For additional information, @square was suggesting the following...

If you can rely on the sequence of the values in the three arrays, and by that I mean, if the values at index 3 in each of the arrays corresponds to the same student, you could do the following:

for (int i = 0; i < nameArray.count; i++) {
    Student* student = [[Student alloc] initWithName:nameArray[i] number:numberArray[i] mark:markArray[i]];
    [theStudents addObject:student];
}

The above relies on you having a class called Student with an init taking name, number and mark. And a mutable array called theStudents.

OTHER TIPS

like this you can try, i dint get ,where you want to pass stud1=(a,1,25); this value, for i=0 you will get stud1=(a,1,25);

NSArray  *name1 = [[NSArray alloc] initWithObjects:@"a",@"b",@"c",nil];
    NSArray  *num2 = [[NSArray alloc] initWithObjects:@"1",@"2",@"3",nil];
    NSArray  *marks3 = [[NSArray alloc] initWithObjects:@"341",@"452",@"353",nil];

    for (int i=0;i<[name1 count]; i++) {

        NSLog(@"%@",[name1 objectAtIndex:i ]);
         NSLog(@"%@",[num2 objectAtIndex:i ]);
         NSLog(@"%@",[marks3 objectAtIndex:i ]);

        // NSLog(@"%@",[obj1 objectAtIndex:i ]);
        // store or display where you want
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top