PHP/SQL Help!

Hello, thank you for taking the time to read this.

Basically, I have a table in a mySQL database that holds people’s inventory on a game and it is stored like this :

[2(17:0)x1]
[SlotID(ItemID:ItemValue)xAmount]

I also have another table which stores the hundreds of available items.

I need it so that I can do something like:

[PHP]

<? $checktheiritem = mysql_query("SELECT * FROM inventory WHERE owner='$logged[username]'"); while ($theiritem = mysql_fetch_array($checktheiritem)) { $amount = AMOUNT; // AMOUNT would need to be the amount from the inventory table. $getitem = mysql_query("SELECT * FROM items WHERE itemid = 'ITEMID'"); // ITEMID would need to be the item id from the inventory table. $item = mysql_fetch_array($getitem); echo "$item[name] x $amount"; } ?>

[/PHP]

Does anyone have any idea how I can separate the amount, itemid, item value etc from the one result [SlotID(ItemID:ItemValue)xAmount]?

I tried doing this, my code is below… but as you can imagine, it is having to check the hundreds of items first which takes about 10 seconds for the script to load. Also I still cannot get the amount.

[PHP]

<? $getitem = mysql_query("SELECT * FROM items"); while ($item = mysql_fetch_array($getitem)) { $checktheiritem = mysql_query("SELECT * FROM inventory WHERE owner='$logged[username]' AND inventory LIKE '%($item[itemid]:$item[value])%'"); $theiritem = mysql_fetch_array($checktheiritem); if ($theiritem != NULL) { echo "$item[name]"; } } ?>

[/PHP]

So basically I want to be able to split them up and define them so for example take out the 2 and define it as $slot, take out the 17 and define it as $itemid, take out the 0 and define it as $value and take out the 1 and define it as $amount.

Any help at all would be appreciated!

Thanks,
Vince.

Well, you are using $theiritem=mysql_fetch_array, so to pull results out of that, you would need to use
something like $amount=$theiritem[‘amount’]; If you are pulling your info using fetch_array, it comes to you as an array. The first part, the key is the name of the field in your database. Such as “amount”. To pull the data or value for this item, you have to use the key. Like: $theiritem[‘amount’] and this is assuming that the name in the database is ‘amount’… Hope that helps…

Sponsor our Newsletter | Privacy Policy | Terms of Service