Valhalla Legends Archive

Programming => Web Development => Topic started by: Blaze on August 09, 2005, 12:03 AM

Title: Mysql question
Post by: Blaze on August 09, 2005, 12:03 AM
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.
Title: Re: Mysql question
Post by: R.a.B.B.i.T on August 09, 2005, 01:57 AM
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 :)
Title: Re: Mysql question
Post by: Blaze on August 09, 2005, 08:08 PM
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. :)
Title: Re: Mysql question
Post by: Maddox on August 10, 2005, 06:19 PM
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);
}
Title: Re: Mysql question
Post by: Maddox on August 12, 2005, 02:27 PM
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?