• Welcome to Valhalla Legends Archive.
 

Mysql question

Started by Blaze, August 09, 2005, 12:03 AM

Previous topic - Next topic

Blaze

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.
Quote
Mitosis: Haha, Im great arent I!
hismajesty[yL]: No

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 :)

Blaze

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
Mitosis: Haha, Im great arent I!
hismajesty[yL]: No

Maddox

#3
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);
}
asdf.

Maddox

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?
asdf.