2011-10-01 14 views
0

좋아, 내 아이폰 애플 리케이션에서 MySQL 데이터베이스에 연결할 수 있어요, 나는 tableview에서 그것을 설정했습니다. 그래서 didSelectRow 메서드를 호출하면 indexRow 번호가 아니라 사용자 ID 번호가 저장됩니다. 내 질문에 어떻게 저장 정보를 나머지 정보를 검색 할 수 있습니다, 그래서 행을 누르면 해당 사용자의 나머지 특정 정보를 나타납니다. 나는 내 iPad에서 이것을 쓰고 있기 때문에 나는 여기에 어떤 코드도 보여주지 않는다는 것을 알고있다. 그래서 나는 당신이 무엇을하려고 노력하고 도움을 주는지 당신이 바라기를 바란다. 감사.데이터베이스에서 데이터 가져 오기.

답변

0

저장된 ID 데이터베이스에서 가져온 내용은 ​​무엇입니까? 내 이해는 사용자가 행을 선택하면 새로운보기로 이동하여 그 이 저장된 ID을 사용하여 db에서 해당 정보를 가져오고 싶습니다.

+0

예. 정확합니다. id는 db에서 얻은 것입니다. 해당 데이터를 가져 와서 새 뷰에 넣는 방법을 이해할 수 없거나 이해할 수 없습니까? –

1

내가 u는 u는 우리가 샘플 코드를 원하는 시간에 해당 배열을 호출 할 수 있습니다 appdel에 배열의 데이터베이스에서 나오는 배열을 저장할 수있는 하나의 방법으로 U 도움이가 여기

입니다 appdb

에 appdb

NSMutableArray *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); 

이것이 도움이 될 것이라고 생각합니다 .....

관련 문제