Putting an array into one mysql table element

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
seanoseanohay
Posts: 25
Joined: Mon Mar 15, 2010 8:27 pm

Putting an array into one mysql table element

Post by seanoseanohay »

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.
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Putting an array into one mysql table element

Post by hallsofvallhalla »

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......
seanoseanohay
Posts: 25
Joined: Mon Mar 15, 2010 8:27 pm

Re: Putting an array into one mysql table element

Post by seanoseanohay »

Sweet!!

I think this is exactly what I need. Thanks
Falken
Posts: 438
Joined: Fri May 08, 2009 8:03 pm

Re: Putting an array into one mysql table element

Post by Falken »

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!
User avatar
MAruz
Posts: 117
Joined: Fri Nov 20, 2009 12:31 pm

Re: Putting an array into one mysql table element

Post by MAruz »

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...
PHP, Java, JavaScript, HTML, CSS, XML, MySQL / Oracle
Photoshop, Illustrator
www.cuddly-zombie.com
seanoseanohay
Posts: 25
Joined: Mon Mar 15, 2010 8:27 pm

Re: Putting an array into one mysql table element

Post by seanoseanohay »

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.
Post Reply

Return to “Advanced Help and Support”