Hi all..
Trying to quash a bug in my High Score code and can't seem to figure it out.
I seem to be missing the first element in the mySQL database.
Here's the code that gets it. and Yes it's executed after the upload is complete.
output reads:
and the Database reads:
*** Sorry forgot to include the php ***
Oops probably need the php too.
thanks
Ian
Trying to quash a bug in my High Score code and can't seem to figure it out.
I seem to be missing the first element in the mySQL database.
Here's the code that gets it. and Yes it's executed after the upload is complete.
Code:
- (void)getsScore
{
// dispatched a AFNetworking in background and gets the highscores //
NSLog(@"Conneting to server");
dispatch_async(kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL:
theLatestHighScoreURL];
[self performSelectorOnMainThread:@selector(fetchedData:)
withObject:data waitUntilDone:YES];
});
}
- (void)fetchedData:(NSData *)responseData {
NSError *error = nil;
NSMutableArray *jsonArray = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
NSMutableArray *hsEnteryArray = [[NSMutableArray alloc]init]; // arrayWithCapacity:[jsonArray count]];
NSLog(@"JSON count: %i",[jsonArray count]);
// so this loop is the problem //
for (NSDictionary *hsDictionary in jsonArray) {
HighScoreKeeper *tempHighScore = [[HighScoreKeeper alloc]retain];
NSMutableString *gotName = [hsDictionary objectForKey:@"userName"];
[tempHighScore setName:gotName];
NSMutableString *gotTimestring = [hsDictionary objectForKey:@"userID"];
[tempHighScore setGameTime:gotTimestring];
NSMutableString *gotCountry = [hsDictionary objectForKey:@"country"];
[tempHighScore setCountry:gotCountry];
NSInteger gotTime = [[hsDictionary objectForKey:@"score"]integerValue];
[tempHighScore setGameTimeSeconds:gotTime];
[hsEnteryArray addObject:tempHighScore];
NSLog(@"DB:%@ %i GsT %@ %@",gotName,gotTime,gotTimestring,gotCountry);
}
// save the data to NSDefault //
NSUserDefaults *defaults= [NSUserDefaults standardUserDefaults];
NSData *worldEncodedObject = [NSKeyedArchiver archivedDataWithRootObject:hsEnteryArray];
[defaults setObject:worldEncodedObject forKey:@"worldHighScoreTable"];
SingletonCentre *myShareSingHS = [SingletonCentre sharedSingleton];
// if I get the update then blank ASS-ume all the queued Items have been sent //
if(myShareSingHS.queuedItems == NO)
{
// Reset the Not Highscore Flag to avoid double entries //
// Upddate the view tells the tableview to update and reload data //
[[NSNotificationCenter defaultCenter] postNotificationName:@"PLEASEVIEWTOUPDATE" object:nil];
}
}
output reads:
Code:
2013-11-17 15:20:32.686 UIScrollView-Paging-networked[2076:207] JSON count: 4
2013-11-17 15:20:32.686 UIScrollView-Paging-networked[2076:207] DB:mayaName 66 GsT 00:01:06
2013-11-17 15:20:32.686 UIScrollView-Paging-networked[2076:207] DB:DawnBooby 66 GsT 00:01:06
2013-11-17 15:20:32.687 UIScrollView-Paging-networked[2076:207] DB:Michel 66 GsT 00:01:06
2013-11-17 15:20:32.687 UIScrollView-Paging-networked[2076:207] DB:AxelJoh 126 GsT 00:02:16 Auckland,New Zealnad
2013-11-17 15:20:32.687 UIScrollView-Paging-networked[2076:207] Saving:mayaName- 00:01:06 66 at (null)
2013-11-17 15:20:32.687 UIScrollView-Paging-networked[2076:207] Saving:DawnBooby- 00:01:06 66 at (null)
2013-11-17 15:20:32.688 UIScrollView-Paging-networked[2076:207] Saving:Michel- 00:01:06 66 at (null)
2013-11-17 15:20:32.689 UIScrollView-Paging-networked[2076:207] Saving:AxelJoh-Auckland,New Zealnad 00:02:16 126 at (null)
2013-11-17 15:20:32.700 UIScrollView-Paging-networked[2076:207] pinged by 1
2013-11-17 15:20:32.700 UIScrollView-Paging-networked[2076:207] reloading data
2013-11-17 15:20:32.700 UIScrollView-Paging-networked[2076:207] loading: mayaName - time:00:01:06 - 66 at:(null)
2013-11-17 15:20:32.701 UIScrollView-Paging-networked[2076:207] loading: DawnBooby - time:00:01:06 - 66 at:(null)
2013-11-17 15:20:32.701 UIScrollView-Paging-networked[2076:207] loading: Michel - time:00:01:06 - 66 at:(null)
2013-11-17 15:20:32.701 UIScrollView-Paging-networked[2076:207] loading: AxelJoh - Auckland,New Zealnad time:00:02:16 - 126 at:(null)
and the Database reads:
Code:
44 00:01:06 Michelle 66 0 <-------- always missing first element ------
45 00:01:06 mayaName 66 0
43 00:01:06 DawnBooby 66 0
42 00:01:06 Michel 66 0
41 00:02:16 AxelJoh 126 Auckland,New Zealnad 0
*** Sorry forgot to include the php ***
Oops probably need the php too.
Code:
<?php
require("config.php");
// to use sqli_query
$link = mysqli_connect("localhost","HighAdmin","password","HighScorerTable") or die("Error " . mysqli_error($link));
// now get the data from the database
//$result = mysqli_query("SELECT * from HighScore_elements_global") or die('query failed');
// creates a query string
$query = "SELECT * FROM HighScore_elements_global" or die("Error in the consult.." . mysqli_error($link));
$result = mysqli_query($link,$query,MYSQLI_STORE_RESULT);
//if(mysqli_num_rows($result)){
if($result->num_rows){
echo '[';
$first = true;
$row=mysqli_fetch_assoc($result);
while($row=mysqli_fetch_array($result,MYSQL_ASSOC)){
// mysqli_fetch_row($result)
// cast results to specific data types
// needs to output something like: "status": "fundraising","funded_amount": 25,"basket_amount": 50,
// This is so Xcode can ingest the data to a NSDictonary
if($first) {
$first = false;
} else {
echo ',';
}
echo json_encode($row);
}
echo ']';
} else {
echo '[]';
}
mysqli_close($link);
thanks
Ian
Last edited: