0

Ok, I am able to connect to the mysql database from my iPhone app, I have set it up in a tableview. So when I call the didSelectRow method it stores the users Id number, not the indexRow number. My question is how can I use that stored id to retrieve the rest of the information, so when the row is pressed it brings up the rest of that users particular Information. I know I am not showing any code here that is because I'm writing this from my iPad, so I hope you cam follow what im trying to do and help. Thanks.

2 Answers 2

1

I can help u in one way that u have to store the array coming from the data base in an array in appdel u can call that array at any time where we want sample code is here

this is the array in appdb

NSMutableArray *fruit_details;

call one method in Appdb

[self readStudentFromDatabase];

then write the code here in that method

NSArray *documentpaths= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentDir = [documentpaths objectAtIndex:0];

databasePath = [documentDir stringByAppendingPathComponent:databaseName];
fruit_details=[[NSMutableArray alloc]init];
//open the database from the users filesystem
if(sqlite3_open([databasePath UTF8String], &database)==SQLITE_OK)
{
    // Setup the SQL Statement and compile it for faster access
    const char *sqlStatement ="select * from stu";
    sqlite3_stmt *compiledStatement;
    if(sqlite3_prepare_v2(database, sqlStatement,-1, &compiledStatement , NULL)== SQLITE_OK)
    {
        // Loop through the results and add them to the feeds array
        while (sqlite3_step(compiledStatement)==SQLITE_ROW) 
        {
            NSString *aName =[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement,0)];
            NSString *amarks=[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement,1)];
            NSString *arank =[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement,2)];
            NSString *aaddr =[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement,3)];
            NSString *aemail =[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement,4)];
            NSString *aphno =[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement,5)];
            NSString *aage =[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement,6)];
            NSString *asex =[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement,7)];
            NSString *adate =[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement,8)];
            NSString *aimage=[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 9)];
            // // Create a new animal object with the data from the database

        //animal *animal_object=[[animal alloc]initWithName:aName description:arollNO url:amarks];

            //add the animal object to the animal ar
            //[animals addObject:animal_object];
            temp=[[NSMutableArray alloc]init];
            [temp addObject:aName];
            [temp addObject:amarks];
            [temp addObject:arank];
            [temp addObject:aaddr];
            [temp addObject:aemail];
            [temp addObject:aphno];
            [temp addObject:aage];
            [temp addObject:asex];
            [temp addObject:adate];
            [temp addObject:aimage];
            [fruit_details addObject:temp];
        }
    }
    sqlite3_finalize(compiledStatement);

}
sqlite3_close(database);

I think this may help u.....

Sign up to request clarification or add additional context in comments.

Comments

0

Is stored id what you get from the db? My understanding is that when user select a row, you want to go to a new view and fetch the corresponding information from the db using that stored id.

1 Comment

Yes that is exactly correct. The id is what I get from the db, I just cannot or don't understand how to fetch the corresponding data and put it into a new view?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.