title: Data fetch from database
body: <p>I stored some information in my server. I used JSON for fetching data. The data is fetch and store to device database and fetch from it. The problem is i have some set images in cat_id=1 &amp; some set images in cat_id=2. Now im using different Array for different set of images like <code>const char *sql = "SELECT id,cat_id,product_image FROM product where cat_id = '1'";</code>, <code>const char *sql = "SELECT id,cat_id,product_image FROM product where cat_id = '2'";</code>. If i use "%@" this it displays all the values.</p>
  
  <p>code:</p>
  
  <p>First set of images:</p>
  
  <pre><code>if (sqlite3_open([path UTF8String], &amp;database) == SQLITE_OK) { 
  
  const char *sql = "SELECT id,cat_id,product_image FROM product where cat_id = '1'"; 
  
  NSLog(@"sql is %s",sql); 
  
  sqlite3_stmt *statement; 
  // int catID = 0; 
  if (sqlite3_prepare_v2(database, sql, -1, &amp;statement, NULL) == SQLITE_OK) { 
  // We "step" through the results - once for each row. 
  while (sqlite3_step(statement) == SQLITE_ROW) { 
  
  
  catName = [[NSString alloc] initWithUTF8String: 
  (const char *) sqlite3_column_text(statement, 2)]; 
  NSLog(@"catName is %@",catName); 
  
  [mArray addObject:catName]; 
  [catName release]; 
  
  // catID = sqlite3_column_int(statement, 0); 
  } 
  } 
  
  
  sqlite3_finalize(statement); 
  } 
  
  else { 
  sqlite3_close(database); 
  NSAssert1(0, @"Failed to open database with message '%s'.", sqlite3_errmsg(database)); 
  // Additional error handling, as appropriate... 
  } 
  </code></pre>
  
  <p>second set of images:</p>
  
  <pre><code>if (sqlite3_open([path UTF8String], &amp;database) == SQLITE_OK) { 
  
  const char *sql = "SELECT id,cat_id,product_image FROM product where cat_id = '2'"; 
  
  
  NSLog(@"sql is %s",sql); 
  
  sqlite3_stmt *statement; 
  // int catID = 0; 
  if (sqlite3_prepare_v2(database, sql, -1, &amp;statement, NULL) == SQLITE_OK) { 
  // We "step" through the results - once for each row. 
  while (sqlite3_step(statement) == SQLITE_ROW) { 
  
  
  tabName = [[NSString alloc] initWithUTF8String: 
  (const char *) sqlite3_column_text(statement, 2)]; 
  NSLog(@"tabName is %@",tabName); 
  
  [tabArray addObject:tabName]; 
  [tabName release]; 
  
  // catID = sqlite3_column_int(statement, 0); 
  } 
  } 
  sqlite3_finalize(statement); 
  } 
  
  else { 
  sqlite3_close(database); 
  NSAssert1(0, @"Failed to open database with message '%s'.", sqlite3_errmsg(database)); 
  // Additional error handling, as appropriate... 
  }
  </code></pre>
  
  <p>} </p>
  
  <p>Im using ActionSheet button click for display array of datas:</p>
  
  <pre><code>-(void)actionSheetClickedButtonAtIndex:(int)buttonIndex {
  
       if (buttonIndex == 0) {
          NSLog(@"button");
  
  
   for (int i = 0; i&lt;[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");
  
  
   for (int i = 0; i&lt;[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) {
  
      }
  }
  </code></pre>
  
  <p>Here i don't want to use cat_id=1 &amp; cat_id=2. I need to pass any parameter  value for increament automatically and get values from table. Because if i change anything the cat_id is increasing.</p>