I have an sqlite db with two tables: 'states' and 'cities'
Code:
states
-------------
stateID (int pk)
stateName (varchar)
cities
-------------
cityID ( int pk)
cityName (varchar)
I know how to load a single database table into a tableview, but I now need to load my sql query results into a grouped table that would look something like this: http://www.netsoftservices.com/groupedlist.jpg
I am just using static arrays to get the picture to look right.
Can anyone point me in the right direction to a tutorial or thread on this very thing? I have searched this site using most of the keywords I can think of and find nothing.
I have an sqlite db with two tables: 'states' and 'cities'
Code:
states
-------------
stateID (int pk)
stateName (varchar)
cities
-------------
cityID ( int pk)
cityName (varchar)
I know how to load a single database table into a tableview, but I now need to load my sql query results into a grouped table that would look something like this: http://www.netsoftservices.com/groupedlist.jpg
I am just using static arrays to get the picture to look right.
Can anyone point me in the right direction to a tutorial or thread on this very thing? I have searched this site using most of the keywords I can think of and find nothing.
Any help would be appreciated!!
Thanks,
Doug
check out the sqlite books tutorial in apple web dev!!!
velkropie,
I used the books tut to learn the sqlite stuff, but there was no grouped table used in that tut. I ended up creating city objects and stuffed them into a states array. Then iterated through both sets of arrays to build the grouped table.
Thanks for your reply though. Seems like replies are getting slower here on this board. People must have gotten busy rewriting their apps for 3.0.
velkropie,
I used the books tut to learn the sqlite stuff, but there was no grouped table used in that tut. I ended up creating city objects and stuffed them into a states array. Then iterated through both sets of arrays to build the grouped table.
Thanks for your reply though. Seems like replies are getting slower here on this board. People must have gotten busy rewriting their apps for 3.0.
Thanks again.
well, they looked grouped to me. it looks like they were sectioned and the views looked group, i'm the expert at iphone...so, maybe i'm missing the definition of grouped tables...
Hi dougdrury,
How did you solved? I too am interested..
Thanks!!
aimos,
The code is a bit too long to post, but here is the steps I took.
I created two NSMutableArrays (sections, cities)
in the ViewDidLoad statement:
I loaded my states table into the sections array via an SQL query.
I then iterated through that sections array and did SQL queries on my cities table to load only the cities that matched that section into a temp cities array and stuffed that into the sections array as a sub item for that index.
Then I reloaded my table using the sections array with numberOfRowsInSection based on the cities count for that section.
Hi Doug,
thanks for reply..
Unfortunately are beginning and earn about different books..
My database is based on this tutorial: iPhone SDK Tutorial: Reading data from a SQLite Database | dBlog.com.au
I can not understand what you mean, is not an example(source) that you or I can send via email the code needed? My email: aemus77@gmail.com
Please help me, many days that is still in my application..
Sorry for my bad English
aimos,
The code is a bit too long to post, but here is the steps I took.
I created two NSMutableArrays (sections, cities)
in the ViewDidLoad statement:
I loaded my states table into the sections array via an SQL query.
I then iterated through that sections array and did SQL queries on my cities table to load only the cities that matched that section into a temp cities array and stuffed that into the sections array as a sub item for that index.
Then I reloaded my table using the sections array with numberOfRowsInSection based on the cities count for that section.
Hope that helps some.
Doug
So, let me see if I get you.
1. SELECT * from `states`
2. Populate a `sections` array with the results of 1.
3. Start For loop on sections array.
4. for each {section_Array as key}, grab the key do a select query on cities and display to the screen?
5. numberOfRowsInSection = cities count for section? -- How did you do this?
I've read some sites talk about using NSDictionaries to break up multi-join tables; is this how you do it?
5.