Valhalla Legends Forums Archive | Web Development | Mysql question

AuthorMessageTime
BlazeI'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.
August 09, 2005, 12:03 am
R.a.B.B.i.TJust a note to Warrior: you can encapsulate other variables in transitive quotes ("").
$query = "SELECT * FROM item_list WHERE ID='$id'";
works just as well Smiley
August 09, 2005, 01:57 am
Blaze
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. Smiley
August 09, 2005, 08:08 pm
Maddox
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:
Code:
$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.

Code:
$res =& $db->query("SELECT * FROM item_list WHERE ID='$id'");
while ($row =& $res->fetchRow()) {
     print_r($row);
}
August 10, 2005, 06:19 pm
Maddox
No, I wrote my own class to wrap around the mySQL calls.

Why reinvent the wheel?
August 12, 2005, 02:27 pm