Alright guys,
Here is my problem. I have a table with a player's city's info in it. This is a pretty long table already and it still needs to store info on the level of each bank and each mine the player has. there will be slots for maybe 5 mines and 5 banks so I do not want to make 10 new elements. Is there a way to fit all the info into just 2 elements? Like an array mines[5] that has the level of each mine and banks[5] that has the level of each bank.
Otherwise I just make mine1, mine2, mine3,...,ect.
Putting an array into one mysql table element
-
- Posts: 25
- Joined: Mon Mar 15, 2010 8:27 pm
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Putting an array into one mysql table element
yeah use substr(), you can cut out characters from a string. It is how I turned a 208 field map system into 13 fields.
You create the string and divide each variable by a certain amount of numbers or a character, you then cut out the variable you need by using a dynamic variable that points to your array place.
Example mine 1 has 150 gold, mine 2 has 25, mine 3 100 gold, you want mine 2's gold amount
$minegold = 150025100
$j = 2 + 1 /////////string starts with 0, so need to add one...
$mine = substr($minegold, $j, 3);
$mine will equal 025......
You create the string and divide each variable by a certain amount of numbers or a character, you then cut out the variable you need by using a dynamic variable that points to your array place.
Example mine 1 has 150 gold, mine 2 has 25, mine 3 100 gold, you want mine 2's gold amount
$minegold = 150025100
$j = 2 + 1 /////////string starts with 0, so need to add one...
$mine = substr($minegold, $j, 3);
$mine will equal 025......
-
- Posts: 25
- Joined: Mon Mar 15, 2010 8:27 pm
Re: Putting an array into one mysql table element
Sweet!!
I think this is exactly what I need. Thanks
I think this is exactly what I need. Thanks
Re: Putting an array into one mysql table element
Although try avoid using too much strings. String modification is often slower than an extra row in the database. Not always, but often...
--- Game Database ---
For all your game information needs!
Visit us at: http://www.gamedatabase.eu today!
For all your game information needs!
Visit us at: http://www.gamedatabase.eu today!
Re: Putting an array into one mysql table element
Sounds like you should start looking into splitting that table up into several smaller ones though. Might be allot of work, but you might need to at some point anyways...
-
- Posts: 25
- Joined: Mon Mar 15, 2010 8:27 pm
Re: Putting an array into one mysql table element
I think Halls way is going to be best here. I thought about just doing a bunch of new cells, but it would be like 40 new cells (one for each building plot in the city). So that is just a 142 long int (2 spots per number to tell what type of building, 2 to show the level) which is much easier...also I think this is going to make it easier to send commands that will modify the city. Instead of specifiying which cell needs to change at a certain time the big number will just change.