Forum Moderators: coopster
This is my code
##Update the database
$eresult = mysql_query("UPDATE user_char set $item_type = '$item' where username = '$username'", $link);
$eresult = mysql_query("SELECT * FROM purchased where username = '$username' AND item_type = '$item_type'", $link) or die ("query 1: " . mysql_error());
$erow = mysql_fetch_array($eresult) or die ("query 1: " . mysql_error());
##Unequip Item
$unequip = mysql_query("UPDATE purchased SET equipped = '0' WHERE username ='$username' AND item_name = '$erow[item_name]'", $link);
##Update the database
$purchasedresult = mysql_query("UPDATE purchased set equipped = '1' where username = '$username' and item_name = '$item'", $link);
My variables are $item_type and $item.
Please help.
I'm assuming you have some sort of online RPG and if you've got multiple tables containing users, inventories, items etc then it's going to be a little difficult to point you in the right direction without the information.
should be this
$eresult = mysql_query("UPDATE user_char set item_type = '$item' where username = '$username'", $link);
I assume item_type is the column nmae of user_char...also try using SET instead of lowercase....I find it more easy to see, but that's me..
--Nick
$eresult = mysql_query("SELECT * FROM purchased where username = '$username' AND item_type = '$item_type'", $link) or die ("query 1: " . mysql_error());
$erow = mysql_fetch_array($eresult) or die ("query 1: " . mysql_error());
##Unequip Item
$unequip = mysql_query("UPDATE purchased SET equipped = '0' WHERE username ='$username' AND item_name = '$erow[item_name]'", $link);
##Update the database
$purchasedresult = mysql_query("UPDATE purchased set equipped = '1' where username = '$username' and item_name = '$item'", $link);
So say I am in my inventory and I have the blunt sword equipped, and I want to equip the sharp sword.
The blunt sword row would look like this
Item Type Name Equipped
weapon blunt sword 1
and the sharp sword would look like this
weapon sharp sword 0
All I want to do is change the "1" to a "0" and the "0" to a "1"
It doesnt look hard but Ive been stumped for 3 days.
I hope this helps.
$unequip = mysql_query("UPDATE purchased SET equipped = '0' WHERE username ='$username' AND item_name = '" . $erow['item_name'] . "'", $link);
Just looking how it is set out, the code is a little hard to handle because the database is not normalised and it appears you'll have a fair bit of data duplication (your database will get larger than it should).
Do you have this RPG online? I'd love to check it out (send me a sticky as per board TOS though).