从数据库中获取数据。
问题描述:
好吧,我可以从我的iPhone应用程序连接到mysql数据库,我已经在tableview中设置它。所以当我调用didSelectRow方法时,它会存储用户Id号码,而不是indexRow号码。我的问题是,如何使用该存储的ID来检索其余的信息,因此当该行被按下时,它会提示剩余的用户特定的信息。我知道我在这里没有显示任何代码,这是因为我正在从iPad上写这个代码,所以我希望你能够跟随即将做的事情和帮助。谢谢。从数据库中获取数据。
答
是存储的ID你从数据库中得到什么?我的理解是,当用户选择一行时,你想要进入一个新的视图,并使用存储的ID从数据库获取相应的信息。
答
我可以帮助ü在u必须存储阵列从数据库即将在数组中appdelü可以调用数组中,我们希望样本代码的任何时间的一种方式是在这里
这是阵列中appdb
appdbNSMutableArray *fruit_details;
呼叫的一种方法
[self readStudentFromDatabase];
然后在这里写的代码在该方法
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);
我认为这可以帮助你......
是的,这是完全正确的。该ID是我从数据库中获得的,我不知道如何获取相应数据并将其放入新视图中? –