I've taken up PHP/SQL recently - I was wondering if someone could answer a question:
Imagine the following tables:
Code:
Foo
ID FooName pictureID Description
1 hello 1 Hello World
Picture
ID Name PictureFileName Description
1 helloPic hello.jpg A picture of Hello
I've been using something like the following (simplified) code:
Code:
…
$query="SELECT * FROM Foo, Picture WHERE foo.pictureID=Picture.id"
$result = mysql_query ( $query, $connection);
while ($resultObject=mysql_fetch_object($result))
{
echo "Foo name: $resultObject->FooName";
echo "some other value: $resultObject->name";
}
…
the code works - but if I were to try and extract $resultObject->Description then it wouldn't work - because there are Description attributes in both tables.
I am currently solving this by using a NameSpace for table attributes like so:
attributeTitle = TableName+AttributeTitle
so Description (in the Foo table) becomes FooDescription and Description in the Picture table becomes PictureDescription. - Similarly id becomes - FooID or PictureID.
This works, but attribute names quickly become very long.
Basically my question is this:
Is this the right way of going about it?