Suppose I have this table:
CREATE TABLE properties (
id int(11) NOT NULL auto_increment,
name varchar(255) NOT NULL default '',
modifierText text NOT NULL,
modifierChar char(1) NOT NULL default '',
modifierVarchar varchar(255) NOT NULL default '',
modifierInt int(11) NOT NULL default '0',
belongsTo int(11) NOT NULL default '0',
PRIMARY KEY (id)
) TYPE=MyISAM;
I also have another table called entry, and this has an id column,
plus a name, body, and date created column.
An unlimited number of properties can be attached to each entry in the
table "entry". The id in the table "entry" is generated by auto
increment in MySql. The field "belongsTo" in the properties table
tells the code which entry in the "entry" table this particular
property belongs to.
Now, I want a function called getEntry() that gets an entry from the
"entry" table, plus all the properties from the the property table,
and brings them together as if they were all there in one table. I get
tripped up on how to do this.
select entry.*, properties.*
from entry, properties
where entry.id = properties.belo ngsTo
order by entry.dateCreat ed
What I'd really like is to get back the mass as an associative array
where every entry from properties has the field name of "name" and
then the associated value (of the "modifier" fields, only should ever
be used for each property, though I can't know which one).
CREATE TABLE properties (
id int(11) NOT NULL auto_increment,
name varchar(255) NOT NULL default '',
modifierText text NOT NULL,
modifierChar char(1) NOT NULL default '',
modifierVarchar varchar(255) NOT NULL default '',
modifierInt int(11) NOT NULL default '0',
belongsTo int(11) NOT NULL default '0',
PRIMARY KEY (id)
) TYPE=MyISAM;
I also have another table called entry, and this has an id column,
plus a name, body, and date created column.
An unlimited number of properties can be attached to each entry in the
table "entry". The id in the table "entry" is generated by auto
increment in MySql. The field "belongsTo" in the properties table
tells the code which entry in the "entry" table this particular
property belongs to.
Now, I want a function called getEntry() that gets an entry from the
"entry" table, plus all the properties from the the property table,
and brings them together as if they were all there in one table. I get
tripped up on how to do this.
select entry.*, properties.*
from entry, properties
where entry.id = properties.belo ngsTo
order by entry.dateCreat ed
What I'd really like is to get back the mass as an associative array
where every entry from properties has the field name of "name" and
then the associated value (of the "modifier" fields, only should ever
be used for each property, though I can't know which one).
Comment