|
Posted by Markstar on 09/29/83 11:56
Hi,
here is a (simplified) version of my problem (it gets more complicated the
further you read, but even an answer to the first problem would help me out
a lot!!!):
With this SQL statement
$sql = mysql_query("SELECT id, type, value, parent FROM testtable WHERE
mainid = xxxx;");
I get the following table:
id type value
------------------------------
1 Name Smith
2 Name Johnson
3 FirstName Michael
4 Name Harris
Now, I want to access Johnson first, then Smith with Michael and finally
Harris.
HOW do I do that???
Apparently the id doesn't really matter as each Name can have many entries
like FirstName, Address, etc. But not every Name has to have those
attributes!
-------------------------------------------------------------------------------------
There is one (and only one) additional field that I have available, a parent
field:
id type value parent
-------------------------------------
a Name Smith NULL
b Name Johnson NULL
c FirstName Michael b
d Name Harris NULL
(where a, b, c and d can be any number)
So, actually in this case I want to access a Name object first and then look
for the row that has the appropriate id as a parent and look up it's
attributes.
In the example this means:
Create a table cell for Smith -> no further entries -> next row.
Create a table cell for Johnson -> accessing all rows with Johnson as
parent -> create cell for Michael -> no further entries -> next row.
Create a table cell for Smith -> no further entries -> next row.
Now, I could the right rows for the parent by starting an extra SQL-query,
but this would mean I constantly have to make SQL-queries! Plus I still
wouldn't know how to sort those results since I can have any number of
attributes!
Afaik, this is basically the same problem as above, I need to access a Name
first and then all the attributes in a certain order. Eg, I have the
attributes FirstName and Address, but of course I want to get the FirstName
before the Address.
How do I do that without extra SQL-queries?
-------------------------------------------------------------------------------------
This get a little more complicated since I also have an attribute that
specifies the order of which the names appear (since the ids are an
enumerating field). So for the example above, it would look like this:
id type value parent
-------------------------------------
a Name Smith NULL
e Order 0 a
b Name Johnson NULL
c FirstName Michael b
f Order 1 b
d Name Harris NULL
g Order 2 c
(where a, b, c, d, e, f and g can be any number)
So, what I actually need to do is get the names, then sort them so according
to their "Order" attribute (again, it may be that some don't have one, in
this case a 0 is assumed).
So, again, HOW do I get to access those Names in the right order and sort
them?
-------------------------------------------------------------------------------------
Oh yes, it gets even a little more tricky (Does it? Maybe it's all very
simple...):
I can also have childs, each with its own attributes again:
id type value parent
-------------------------------------
a Name Smith NULL
e Order 0 a
b Name Johnson NULL
c FirstName Michael b
f Order 1 b
d Name Harris NULL
g Order 2 c
h Child Owen d
i Order 1 h
j Child O'Neil d
k Order 0 j
(where a, b, c, d, e, f and g can be any number)
So it looks like this:
Smith
O'Neil
Owen
Johnson (with Michael-Attribute)
Harris
or in other words:
Name level0 level1
----------------------------------
Smith 0 (0)
O'Neil 0 0
Owen 0 1
Johnson 1 (0)
Harris 2 (0)
Now, I could just add fields, ordering this would be pretty simple (even
though I don't know the depth of the tree, meaning I don't know how many
generations there are). But I only have this info as another attribute and I
don't know how to access it without making a SQL-query for each one of them
(which is not feasible).
THANK YOU TO EVERYONE WHO READ THIS FAR!!!!!
Obviously I would greatly appreciate any help/insights you can give me!!!
Kind Regards
Markus
Navigation:
[Reply to this message]
|