Here is my problem. I want to make a character inventory. Each user that subscribes to my web site has a character. He can buy things, win money, etc. For the money it is very simple, for each recordset a money column is allocated. But what about the inventory? I really don’t know how to do it.
I tried making a table in mysql with all the objects: (the ~ are used to make space between columns in this exemple)
ex:
[B]Item table:
[B]ID~~~~[B]Name of item~~~~~~ [B]Description~~~~~~ [B]Price
1Pencil~~~~~~~a pencil to write~~~~~~~~~~1$
2Eraser~~~~~~an eraser to erase~~~~~~0.50$~~~
etc…
and then for each recordset (or each item) make a column in the user table of type ‘int’ so each user has a specified amount of each item he bought
ex:
[B]users table:
user name~~~~~pass~~~~ money~~~~[I]pencil~~~(~~~…[I]next column would be the next item in the items table
lunfel
bobby
megaman21
…
But for some reason I can’t add the objects dynamicaly into the mysql db.
Here is my PHP code
[code=php]
include(“connect.conf.php”);
$con=mysql_connect($host,$username,$password);
mysql_select_db($bd);
$sql_item=”SELECT nom FROM items”;
$query_item=mysql_query($sql_item,$con); //GET THE ITEMs IN THE ITEMS TABLE
$i=0;
while($i<mysql_num_rows($query_item)) //ADDING THE ITEMS INTO THE DATABASE. LOOPS THE NUMBER OF TIME THERE IS RECORDSETS
{
$result_item=mysql_fetch_array($query_item);
$current_item=$result_item[0]; //PASSING THE VALUE TO A GLOBAL VAR
echo $current_item; //TEMPORARY CODE TO CHECK IF THE VAR HAS A VALUE (AND IT HAS ONE)
@mysql_query(“ALTER TABLE eleves ADD . $current_item . INT(3) DEFAULT ‘0’ NOT NULL”,$con); //ALTERING THE TABLE ELEVES (IN THIS CASE ELEVES IS EQUAL TO MY USERS TABLE) DEPENDING ON ITEM STORED IN $CURRENT_ITEM
$i++; //ITERATION OF MY LOOP
}
As you can see, the line where I alter the table there is something wrong
[code=php]@mysql_query(“ALTER TABLE eleves ADD . $current_item . INT(3) DEFAULT ‘0’ NOT NULL”,$con);
It is not the proper way to add a concocted string as argument. This is one of many possibilities I tried.
I tried all of these:
[code=php]
@mysql_query(“ALTER TABLE eleves ADD” . $current_item . ” INT(3) DEFAULT ‘0’ NOT NULL”,$con);
@mysql_query(“ALTER TABLE eleves ADD . ‘$current_item’ . INT(3) DEFAULT ‘0’ NOT NULL”,$con);
@mysql_query(“ALTER TABLE eleves ADD $current_item INT(3) DEFAULT ‘0’ NOT NULL”,$con);
@mysql_query(“ALTER TABLE eleves ADD ” $current_item ” INT(3) DEFAULT ‘0’ NOT NULL”,$con);
@mysql_query(“ALTER TABLE eleves ADD ‘ “$current_item” ‘ INT(3) DEFAULT ‘0’ NOT NULL”,$con);
None of these worked out except one
[code=php]
@mysql_query(“ALTER TABLE eleves ADD . ‘$current_item’ . INT(3) DEFAULT ‘0’ NOT NULL”,$con);
Outputing an item with the name $current_item and not his value. All other wouldn’t do anything
When I put the string into a var and then outputed it, it would be the name of the item name that would appeard normally as I wanted but in the db it didn’t make a change
I was using
[code=php]
$myquery=”ALTER TABLE eleves ADD” . $current_item . ” INT(3) DEFAULT ‘0’ NOT NULL”;
echo $myquery;
[B][SIZE=3]I really don’t know what to do please help anyone. If you find a way simpler to do what I want to do (make columns using recordsets) please tell me.