Help I am confused about how to get a inventory system going

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

Help I am confused about how to get a inventory system going

Post by Mythic Fr0st »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Well, my game is coming along well, but the next part I am really struggling with is inventory, I usually can think of ways to do things, but this im not sure

(basically, you start off with a dagger & and a spell, which you can buy others from the shop)

so im not sure how to do this because, i've dont even know if its possible to have string arrays in MySQL

(probably is but I dont know) anyway, this is what i've currently got...

Code: Select all

<php
foreach ($inv as $key => $shw)
{
$ihtw='<option value='.$inv[$key].'>'.$inv[$key].'</option>';
echo $ihtw;
}
?>
</select>
</form>
and no it doesnt work... I just see $inv[$key] and so on, could I get some help plz (it'd be good if I could be told how to make arrays in MySQL)

I did notice once there was something called 'index' does that have anything to do with it


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

$ihtw='<option value='.$inv[$key].'>'.$inv[$key].'</option>';
Should be

Code: Select all

$ihtw = '<option value='.$key.'>'.$key.'</option>';
If you need to store an array into MySQL, you can use the serialize() function on it to turn it into a string. Then when you pull the serialized array from MySQL, you can get it back into an array by using unserialize().
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply