Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Loading FMDB data into HTML / Webview

trisvandistrisvandis Posts: 71Registered Users
Hello,

I'm a bit stuck trying to write some code that pulls info from a SQLite database and loads it into a webview, via HTML. I'm using FMDB as a wrapper, and currently have this as my code:


-(NSMutableArray *) getNowOffers
{
NSMutableArray *nowOffers = [[NSMutableArray alloc] init];

FMDatabase *db = [FMDatabase databaseWithPath:[Utility getDatabasePath]];

[db open];
[db setLogsErrors: TRUE];
[db setTraceExecution: TRUE];

[self getTimeAndDate];

FMResultSet *results = [db executeQuery:@\"select s.id as i, s.description as offerdescription,r.id, r.logo, s.title as name from restaurant r, specialoffer s where r.id=s.restaurant_id and r.id = (:rest) and case (:weekDay) when 1 then s.sun_start < (:currentTime) and s.sun_end > (:currentTime) and sun_valid='Y' when 2 then s.mon_start < (:currentTime) and s.mon_end > (:currentTime) and mon_valid='Y' when 3 then s.tue_start < (:currentTime) and s.tue_end > (:currentTime)and tue_valid='Y' when 4 then s.wed_start < (:currentTime) and s.wed_end > (:currentTime) and wed_valid='Y' when 5 then s.thu_start < (:currentTime) and s.thu_end > (:currentTime) and thu_valid='Y' when 6 then s.fri_start < (:currentTime) and s.fri_end > (:currentTime) and fri_valid='Y' when 7 then s.sat_start < (:currentTime) and s.sat_end > (:currentTime) and sat_valid='Y' end order by r.id\" withParameterDictionary:daytimeDictionary];


while([results next])
{
if ([results stringForColumn:@\"name\"] == NULL) {
offerShortDescription = @\"No Offers Available\";
} else {

offerShortDescription = [results stringForColumn:@\"name\"];
}

offerFullDescription = [results stringForColumn:@\"offerdescription\"];


[nowOffers addObject:offerFullDescription];
[nowOffers addObject:offerShortDescription];

}

[db close];

return nowOffers;
}


this part puts the data pulled by the FMDB query into html....


-(void) loadOffers {
//create table
NSString *html = @\"<html><body leftmargin='0px' topmargin='0px' marginwidth='0px' marginheight='0px'><table width='100%' style='border: 0px; padding:2px; spacing:1px'>\";

NSMutableString *html2 = [NSMutableString stringWithFormat:@\"<tr><td align='center' style='background-color:#ccffcc;font-size:large;'>OFFERS ON NOW</td><td style='background-color:#ffffff;'> %@</td></tr>\", offerShortDescription];
NSString *html3 = [html stringByAppendingString: html2];

NSMutableString *html4 = [NSMutableString stringWithFormat:@\"<td style='background-color:#ffffff;'>%@</td></tr>\", offerFullDescription];

NSString *html5 = [html3 stringByAppendingString: html4];


[webView loadHTMLString:html5 baseURL:[NSURL URLWithString:@\"\"]];


}


At the moment this works, but it only displays the first row from the database. So if the query pulls back multiple entries, it will only ever display one. How would I go about displaying the other entries and adding them to my html??

Could I implement some sort of while loop within the html? And do I need to us NSIndexPath in some way to display the multiple entries?

Any help/suggestions would be greatly appreciated!

Many thanks
Sign In or Register to comment.