I have a problem with my iPhone application, i am trying to connect to my PHP script to get information about something.
I have this code that takes the respone from PHP Link(total tables) and puts it into responseRandomID.
But when i try and use it in a Random function, it comes up with an error when i try and run it?
connectionDidReciveData:
if(connection == connectionRandomID) {
NSString *temp = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
responseRandomID = [temp intValue];
}
connectionDidFinishLoading:
if(connection == connectionRandomID) {
randomid = (int)1 + arc4random() % (1-responseRandomID+1);
}
EDIT: This only happends when i have only 1 row in my database? But when i have 2 it crashes?
can lead to / by 0 if responseRandomId == 2
if hardcoded e.g. 2 % 0 – the compiler catches it
if given via variable (as in your case) :