2011-10-01 274 views
0

好吧,我可以從我的iPhone應用程序連接到mysql數據庫,我已經在tableview中設置它。所以當我調用didSelectRow方法時,它會存儲用戶Id號碼,而不是indexRow號碼。我的問題是,如何使用該存儲的ID來檢索其餘的信息,因此當該行被按下時,它會提示剩餘的用戶特定的信息。我知道我在這裏沒有顯示任何代碼,這是因爲我正在從iPad上寫這個代碼,所以我希望你能夠跟隨即將做的事情和幫助。謝謝。從數據庫中獲取數據。

回答

0

存儲的ID你從數據庫中得到什麼?我的理解是,當用戶選擇一行時,你想要進入一個新的視圖,並使用存儲的ID從數據庫獲取相應的信息。

+0

是的,這是完全正確的。該ID是我從數據庫中獲得的,我不知道如何獲取相應數據並將其放入新視圖中? –

1

我可以幫助ü在u必須存儲陣列從數據庫即將在數組中appdelü可以調用數組中,我們希望樣本代碼的任何時間的一種方式是在這裏

這是陣列中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); 

我認爲這可以幫助你......