Valhalla Legends Forums Archive | Web Development | Mysql question

AuthorMessageTime
KkBlazekK
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.
August 9, 2005, 5:03 AM
R.a.B.B.i.T
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 :)
August 9, 2005, 6:57 AM
KkBlazekK
[quote author=Warrior link=topic=12477.msg123688#msg123688 date=1123570260]
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.
[/quote]

Thats a great idea, thanks. :)
August 10, 2005, 1:08 AM
Maddox
[quote author=Warrior link=topic=12477.msg123688#msg123688 date=1123570260]
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);
      }
  }
[/code]

If I misunderstood please say so, but I think I read correctly.

HTH.
[/quote]


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);
}
[/code]
August 10, 2005, 11:19 PM
Maddox
[quote author=Warrior link=topic=12477.msg123882#msg123882 date=1123717076]
No, I wrote my own class to wrap around the mySQL calls.
[/quote]

Why reinvent the wheel?
August 12, 2005, 7:27 PM

Search