Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9156265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:44:09+00:00 2026-06-17T12:44:09+00:00

My app is for expenses in every month, I have table with name Expense

  • 0

My app is for expenses in every month, I have table with name Expense contain 4 columns (type, ExpenseMonth, amount and Name) ,every day I insert data for my expenses now How I can display the Expense for every day in a section in the table view?

e.g : if the date is 2-1-2013 I want to retrieve the expense of this day only and so on for other days.

I write the below query but every section retrieve the same data.

const char *sql ="select Name from Expense  where strftime('%m-%d',ExpenseMonth) Group by ExpenseMonth order by ExpenseMonth desc";

This my code after correcting….

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

NSMutableArray *Dateo= [[NSMutableArray alloc]init];
NSMutableArray *NAMeA= [[NSMutableArray alloc]init ];

if (sqlite3_open([[AppDelegate getDBPath] UTF8String], &database) == SQLITE_OK) {

    const char *sql ="select ExpenseMonth,count(*) as day from Expense  where strftime('%m',ExpenseMonth)=strftime('%m','now') group by ExpenseMonth order by ExpenseMonth desc";
    sqlite3_stmt *selectstm;
    int result = sqlite3_prepare_v2(database, sql, -1, &selectstm, NULL);
    if( result== SQLITE_OK) {
        while(sqlite3_step(selectstm) == SQLITE_ROW) {
            NSString *dateAndTime=[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstm, 0)];
            NSInteger numofday=sqlite3_column_int(selectstm,1);
            MaxEntity *DatTime=[[MaxEntity alloc]initWithDate:dateAndTime andnumofDay:numofday];                
            [Dateo addObject:DatTime];
            NSLog(@"Date %@",dateAndTime);
            for (NSString *str in Dateo) {
                NSString *querySQL =[NSString stringWithFormat:@"select Name, amount from Expense  where ExpenseMonth=\"%@\" order by ExpenseMonth desc",dateAndTime];
                const char *query_stmt = [querySQL UTF8String];
                sqlite3_stmt *selectstmt;
                int result = sqlite3_prepare_v2(database, query_stmt, -1, &selectstmt, NULL);
                if( result== SQLITE_OK) {
                    while(sqlite3_step(selectstmt) == SQLITE_ROW) {
                        NSString *NAMe=[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 0)];
                        NSString *Amount=[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)];
                        MaxEntity *NM=[[MaxEntity alloc]initWithName:NAMe andAmount:Amount];
                        [NAMeA addObject:NM];                          
                        MaxEntity *curItem = [NAMeA objectAtIndex:indexPath.section ]; //Get the model information at row location.
                        cell.textLabel.text = curItem.name;
                        NSLog(@"text%@",cell.textLabel.text);

                        [NAMeA removeLastObject];
                        [Dateo removeLastObject];
                    }
                }
                sqlite3_finalize(selectstmt);
             }
        }
    }
    sqlite3_finalize(selectstm);
    sqlite3_close(database);
}

return cell;

}

It reads the date and then selects the data depending on the date, after done retrieving the data it return again to the database to retrieve the first date again and throws an exception in this line, Plz can any one help me to stop the select statement when retrieve all date???
MaxEntity *curItem = [NAMeA objectAtIndex:indexPath.section ];

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:44:10+00:00Added an answer on June 17, 2026 at 12:44 pm

    select Name from Expense where strftime('%m-%d',ExpenseMonth) Group by ExpenseMonth order by ExpenseMonth desc

    Your where clause just calculates a string value, it doesn’t compare anything, so it will always return the same results. It needs to be in the format of where ExpenseMonth = .... So, for a given section/day you would need to set a query like:

    NSString *sql = [NSString stringWithFormat:@"select Name from Expense where ExpenseMonth = %@ Group by ExpenseMonth order by ExpenseMonth desc", sectionDate];

    (Sorry, this is in Objective-C, which is what I work in, but should give you the idea of how to do it in C++, which I assume is what you’re working in.)

    Basically, loop through dates substituting the date string (sectionDate) into the SQL statement (replaces the “%@”) for each section of the table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a small expenses cake app. Basicaly I have a expenseClaim
So I have a simple personal finance app that needs to perform recurring expense
So I have this app, where users create expense reports. Each report has many
I'm building a Rails app to track expenses/debts among members of a group, let's
I'm new to django, and as a learning app, I'm building an expense logging
I'm building an Android app, and have set up a base DBObject class to
app/models/zombie.rb class Zombie < ActiveRecord::Base attr_accessible :name validates :name, presence: true end spec/models/zombie_spec.rb require
How does one code this scenerio in iphone sdk? In an expense app, when
App Store We have been developing an app for quite some time now for
I've seen the GWT Expenses app from GWT SDK is using single module structure.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.