I'm working on php project that requires users to have an inventory and I'm using a mysql database to store what things this user has. I'm wondering how you people would set up the table for this? I've thought of having a string with spaces splitting each item, which would work. I've also thought of having a boolean value for each item but that would take up quite a bit of space. Are there any other options that are any better then these two?
Any suggestions/help/comments are greatly appreciated.
Just a note to Warrior: you can encapsulate other variables in transitive quotes ("").
$query = "SELECT * FROM item_list WHERE ID='$id'";
works just as well :)
Quote from: Warrior on August 09, 2005, 01:51 AM
Have two tables, one with a list of users and thier IDs and another with items.
Have the item table store the ID of the user it belongs to.
...
If I misunderstood please say so, but I think I read correctly.
HTH.
Thats a great idea, thanks. :)
Quote from: Warrior on August 09, 2005, 01:51 AM
Have two tables, one with a list of users and thier IDs and another with items.
Have the item table store the ID of the user it belongs to.
Then you could do something like:
$query = "SELECT * FROM item_list WHERE ID='" . $id . "'";
if (!($db->query($query))) {
echo mysql_error();
} else {
while ($fA = mysql_fetch_array($query)) {
print_r($fA);
}
}
If I misunderstood please say so, but I think I read correctly.
HTH.
Are you using PEAR's DB class? Then it would be something like this.
$res =& $db->query("SELECT * FROM item_list WHERE ID='$id'");
while ($row =& $res->fetchRow()) {
print_r($row);
}
Quote from: Warrior on August 10, 2005, 06:37 PM
No, I wrote my own class to wrap around the mySQL calls.
Why reinvent the wheel?