gpt4 book ai didi

iphone - 从数据库获取数据。

转载 作者:行者123 更新时间:2023-11-29 04:57:42 24 4
gpt4 key购买 nike

好的,我可以从我的 iPhone 应用程序连接到 mysql 数据库,我已经在 TableView 中设置了它。因此,当我调用 didSelectRow 方法时,它存储用户 ID 号,而不是 indexRow 号。我的问题是如何使用存储的 id 来检索其余信息,因此当按下该行时,它会显示该用户的其余特定信息。我知道我没有在此处显示任何代码,因为我是通过 iPad 编写此内容的,所以我希望您能够关注我正在尝试做的事情并提供帮助。谢谢。

最佳答案

我可以用一种方式帮助你,你必须将来自数据库的数组存储在appdel中的数组中,你可以随时调用该数组,我们想要的示例代码在这里

这是appdb中的数组

NSMutableArray *fruit_details;

调用Appdb中的一个方法

[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);

我认为这可能对你有帮助......

关于iphone - 从数据库获取数据。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7618480/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com