Get data from database.
Ok, I am able to connect to the mysql databa开发者_JAVA百科se 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.
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.....
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.
精彩评论