iphone - Data fetch from database -
i stored information in server. used json fetching data. data fetch , store device database , fetch it. problem have set images in cat_id=1 & set images in cat_id=2. im using different array different set of images const char *sql = "select id,cat_id,product_image product cat_id = '1'";
, const char *sql = "select id,cat_id,product_image product cat_id = '2'";
. if use "%@" displays values.
code:
first set of images:
if (sqlite3_open([path utf8string], &database) == sqlite_ok) { const char *sql = "select id,cat_id,product_image product cat_id = '1'"; nslog(@"sql %s",sql); sqlite3_stmt *statement; // int catid = 0; if (sqlite3_prepare_v2(database, sql, -1, &statement, null) == sqlite_ok) { // "step" through results - once each row. while (sqlite3_step(statement) == sqlite_row) { catname = [[nsstring alloc] initwithutf8string: (const char *) sqlite3_column_text(statement, 2)]; nslog(@"catname %@",catname); [marray addobject:catname]; [catname release]; // catid = sqlite3_column_int(statement, 0); } } sqlite3_finalize(statement); } else { sqlite3_close(database); nsassert1(0, @"failed open database message '%s'.", sqlite3_errmsg(database)); // additional error handling, appropriate... }
second set of images:
if (sqlite3_open([path utf8string], &database) == sqlite_ok) { const char *sql = "select id,cat_id,product_image product cat_id = '2'"; nslog(@"sql %s",sql); sqlite3_stmt *statement; // int catid = 0; if (sqlite3_prepare_v2(database, sql, -1, &statement, null) == sqlite_ok) { // "step" through results - once each row. while (sqlite3_step(statement) == sqlite_row) { tabname = [[nsstring alloc] initwithutf8string: (const char *) sqlite3_column_text(statement, 2)]; nslog(@"tabname %@",tabname); [tabarray addobject:tabname]; [tabname release]; // catid = sqlite3_column_int(statement, 0); } } sqlite3_finalize(statement); } else { sqlite3_close(database); nsassert1(0, @"failed open database message '%s'.", sqlite3_errmsg(database)); // additional error handling, appropriate... }
}
im using actionsheet button click display array of datas:
-(void)actionsheetclickedbuttonatindex:(int)buttonindex { if (buttonindex == 0) { nslog(@"button"); (int = 0; i<[marray count]; i++ ) { nslog(@"index %d",i); // imgview1=[[uibutton alloc]initwithframe:cgrectmake(20+(i*74), 500, 72, 72)]; imgview1=[[uibutton alloc]initwithframe:cgrectmake(20+(i*74), 0, 72, 72)]; width = width + 20+(i*74); [imgview1 settag:i+1]; [imgview1 addtarget:self action:@selector(arraysofsclicked:) forcontrolevents:uicontroleventtouchupinside]; [imgview1 setimage:((mysof *)[marray objectatindex:i]).photo forstate:uicontrolstatenormal]; [scrollview addsubview:imgview1]; // [myscroll addsubview:imgview1]; } } else if (buttonindex == 1) { nslog(@"button 1"); (int = 0; i<[tabarray count]; i++ ) { nslog(@"index %d",i); // imgview1=[[uibutton alloc]initwithframe:cgrectmake(20+(i*74), 500, 72, 72)]; imgview1=[[uibutton alloc]initwithframe:cgrectmake(20+(i*74), 0, 72, 72)]; width = width + 20+(i*74); [imgview1 settag:i+1]; [imgview1 addtarget:self action:@selector(arraysofsclicked:) forcontrolevents:uicontroleventtouchupinside]; [imgview1 setimage:((mysof *)[tabarray objectatindex:i]).photo forstate:uicontrolstatenormal]; [scrollview addsubview:imgview1]; // [myscroll addsubview:imgview1]; } } else if (buttonindex == 2) { nslog(@"button 2"); } else if (buttonindex == 3) { } }
here don't want use cat_id=1 & cat_id=2. need pass parameter value increament automatically , values table. because if change cat_id increasing.
you can change properties of cat_id
not auto increment. also, auto increment should triggered when insert new row table.
it seems cat_id
foreign key other table describing product category. use update table
syntax change record (e.g. new image), leaving cat_id
unchanged.
if user changes category of product, set new cat_id
.
in sqlite substitute variables ?
, sqlite_bind_*
function:
const *char sql = "select id, cat_id, product_image product " "where cat_id = ?"; ... if (sqlite3_prepare_v2(database, sql, -1, &statement, null) == sqlite_ok) { if (sqlite3_bind_int(sql, 1, yourcatid) == sqlite_ok) { // iterate through results sqlite3_step } }
Comments
Post a Comment