Welcome to the Browser-Base Game Zone forums!
function createOffice($country,$city,$assigner_id,$name,$type,$officenumber=NULL) {... return officeid;}// Country$country=6; // Central government offices$city=0;createOffice($country,$city,0,'Inspector',99); // City X offices$city=5;$assigner_id=createOffice($country,$city,0,'Captain',100);createOffice($country,$city,$assigner_id,'Guard',101,1);createOffice($country,$city,$assigner_id,'Guard',101,2);// City Y offices$city=6;$assigner_id=createOffice($country,$city,0,'Captain',100);createOffice($country,$city,$assigner_id,'Guard',101,1);createOffice($country,$city,$assigner_id,'Guard',101,2);
office_id = country+city*(100)+type*(100*1000)+officenumber*(100*1000*100)
Done, thanks.BTW, recalculating 1D array to multidimensional array is a proper software design and is used extremely often, that's how it was frequently done in C and in ASM you don't even have other options (malloc() just allocate a linear block of memory and you have to recalculate the 2nd dimension by hand). You just got spoiled by the relational databases
Quote from: Chris on January 12, 2012, 11:00:32 AMDone, thanks.BTW, recalculating 1D array to multidimensional array is a proper software design and is used extremely often, that's how it was frequently done in C and in ASM you don't even have other options (malloc() just allocate a linear block of memory and you have to recalculate the 2nd dimension by hand). You just got spoiled by the relational databases office_id = country+city*(100)+type*(100*1000)+officenumber*(100*1000*100)that is not recalculating 1D array to multidimensional array, this is making a value of some other values.. its similar to $office_id = md5("test"); you will never be able to recalculate it back. and you cannot compare arrays with databases tbh..
I want new offices to be added easily and at least half automaticly.
why make it simple, clear and proper when you can make it obscure and difficult
lets say, we have country_id 2, city 4, type is 5 officenumber is 6. so the office id would beoffice_id = 2+4*(100)+5*(100*1000)+6*(100*1000*100)office_id =60500402.Well now explain me , how will you get from this number the country_id, the city, the type and officenumber?
Now remember everyone... Chris' game is his game, and we're just here to offer advice on how he can solve some of the challenges he's been running into.