/    Sign up×
Community /Pin to ProfileBookmark

Storing arrays in DB????????

What happens if I write the following text in a database row call numbers:

“one”, “two”, “three”, “four”

and after I try to recover it like this:

[code=php]$result= mysql_query(“SELECT numbers FROM arrays” ,$link);
while ($row = mysql_fetch_array($result)){
$numbers=array($row[‘numbers’]);}[/code]

I thought I will recover an array, but it doesn’t work.
Any hints?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 27.2005 — I'm thinking maybe you need to eval() it:
[code=php]
eval("$numbers=array({$row['numbers']});");
[/code]
Copy linkTweet thisAlerts:
@ShrineDesignsMar 27.2005 — use serialize() on the array before saving it to the database then use unserialize() to make it an array again
Copy linkTweet thisAlerts:
@PowerbossOct 14.2006 — say I have a place in DB for people and everything about them...

then in another place I have say everything they collect.

and link it to the table about them to reconize who it belongs to.

say item 1 item 2 item 3...

how do i seperate items 1 2 and 3 to store certain types of those items?

like say item 1 small items 2 medium and 3 large.

then be able to pull them out of database in a dropdown menu or a combo box
Copy linkTweet thisAlerts:
@SheldonOct 15.2006 — more planning would help, maybe a uniqe id that matched the persons database and their items database
Copy linkTweet thisAlerts:
@PowerbossOct 15.2006 — I guess a little more "in depth" explaination wouldn't hurt...

I'm building my own game right now on my computer in php. using www.dyndns.com to give myself a webaddress so my IP doesn't get given out and people can play my game. The game address is at http://arctura.game-host.org

The game is so far stable.

What I'm working on trying to do next is in the database make 3 places inventory is stored. #1 Player equipped, #2 Player carrying, #3 Item masterlist

I have like 17 type of armors (see website i put it there) not including the weapon. each item can give a bonus to all 6 stats maybe a gold increasement drop (i suppose that could be coded in the battle pages later on) and maybe an exp drop rate too.

I'm wanting all the items in the #3 portion to carry all the stats simple. #1 on player will just have the ID of whatever #3 has not sure if it's a good idea to seperate all armors into individual tables or not or just to seperate weapons and armors armors i mean can be easily seperated by a type column...

But in the #2 portion is where i'm having trouble. in php I'm wanting to store what a player has carrying they they found while wandering around or bought from shops.

(no limit to how much they can carry as of yet)

I want say something like for ID = 1 in #2 table ID #2 table = ID #3 the masterlist table and in #2 have a QTY column to show how much that player is carrying then list in alphabetical order when a player views his inventory. Maybe for dropping and selling have a sell sell stack and sell all option. I Don't want the equipped items to show up in inventory and i don't want more than 1 item to show up in a players inventory so say #3 ID 1 is knife value 1 bonuses all 0's and a player is carrying 2 extra and equipped one

I want something like player DB to look like this or something

members table #1 above of equipped items

ID 1 Charactername Powerboss Weapon Knife(this would be 1) armors ETC

next is masterlist table #3

ID 1 Name Knife bonuses 0's (seperated for greater bonuses in one thing and not another) value 1

Last is player carrying 2 extra in table #2 char_info table

ID 1 = autonum to ID in members table to show for character

experience = players expierence (already done)

helm = players carried head armor pieces

continue for all armors seperate

Weapons = ID(1) of #3 and have a simple second column called QTY and value for ID(1) = 2 QTY

and when player views carried weapons he sees Knife(2) for 2 carried.

too much or do you need more info?
×

Success!

Help @Perfidus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...