Parent Child Data - Populate within a Dropdown
Hi All ...
I have a mysql database with the following fields
ID (Int) - Title (VarChar) - ParentID (Int)
This table is used to display categories with it's parent. Categories with the ParentID of 0 means that it is a root category.
What'm trying to do is query the database and populate all values (with it's parent & child(s)) within a regular html dropdown box.
So the output of the dropdown whould look like:
Home
Home > Sub Cat 1
Home > Sub Cat 1 > Sub Sub Cat 1
Home > Sub Cat 1 > Sub Sub Cat 2
Home > Sub Cat 1 > Sub Sub Cat 3
Home > Sub Cat 2 > Sub Sub Cat 1
Home > Sub Cat 2 > Sub Sub Cat 2
Home > Sub Cat 3
Home > Sub Cat 4
Home > Sub Cat 4 > Sub Sub Cat 1
Home > Sub Cat 5
Any ideas on how I can accomplish this?
Many Thanks
Shafiq
As far as I know you cannot elegantly handle this sort of datastructure in MySQL (this is based on 5min of googling). If you had Oracle you could use CONNECT BY PRIOR, and with SQL Server one can use Common Table Expressions to effect much the same thing (except in a pretty clunky fashion, IMO).
As far as I can tell, MySQL has neither of those options. You'll need to do some sort of horrific recursive proc, or something like that. Although I saw references to MySQL not even being able to do that (I didn't check how contemporary those comments were).
If you can possibly ditch that way of modelling your data - it really doesn't scale so well - have a look at nested set hierarchies:
http://en.wikipedia.org/wiki/Nested_set_model
The only modification I make to that is to store the parent with each node too, which makes sibling operations much easier. Nested sets work really well with hierarchical look-ups though.
Adam
Similar Messages
-
Getting parent-child data from a single column in a table
Hi,
I have a parent-child data in a column.
Eg:
0
00
01
010
011
1
10
11
These values are present in the single column itself. My need is to get the parent values for the given child value.
For eg: If I am giving the input as 011, the query should return all its parents, i.e. 01 and 0
Could you please give me any inputs on this?
Thanks,
GVFrank Kulash wrote:
Assuming that each child's id is formed by adding exactly one character to the end of its parent's id:
SELECT id
FROM table_x
START WITH id = :target_id
CONNECT BY PRIOR id LIKE id || '_';
Small tweak to yours Frank if it's just the parents that need identifying...
SQL> ed
Wrote file afiedt.buf
1 with t as (select '0' as x from dual union all
2 select '00' from dual union all
3 select '01' from dual union all
4 select '010' from dual union all
5 select '011' from dual union all
6 select '1' from dual union all
7 select '10' from dual union all
8 select '11' from dual)
9 -- end of test data
10 SELECT x
11 FROM t, (select '&required' as req from dual) req
12 WHERE x != req.req
13 START WITH x = req.req
14* CONNECT BY PRIOR x LIKE x || '_'
SQL> /
Enter value for required: 011
old 11: FROM t, (select '&required' as req from dual) req
new 11: FROM t, (select '011' as req from dual) req
X
01
0
SQL> /
Enter value for required: 11
old 11: FROM t, (select '&required' as req from dual) req
new 11: FROM t, (select '11' as req from dual) req
X
1
SQL> -
Getting parent-child data into an Oracle level-based OLAP hierarchy
We have some organisational data which we need to represent in an Oracle OLAP 10g dimension, preferably populated using Warehouse Builder.
The organisational hierarchy is listed as parent-child pairs, and is both ragged (unbalanced) and skip-level (noncovering). This would lend itself to a value-based hierarchy, but our client would rather we use ROLAP rather than MOLAP, i.e. avoid the use of an Analytical Workspace, which rules out the use of a value-based hierarchy.
Is there a straightforward way to populate a level-based hierarchy using parent-child pair data, and if so how can it be done?
Pointers to tutorials would be welcome, especially if they use Warehouse Builder.If you have an Oracle DB have a look on the CONNECT BY PRIOR functionality.
regards
John
http://obiee101.blogspot.com -
I have a parent/child data report but am not seeing the data for the child portion. I have a repeating frame which is printing the parent portion. Within that frame I have another repeating frame which should be displaying the child portion of the data but it is not. I have a data link between the two based on an id number. I think the problem is that the child portion is not being passed the id number from the parent. I have some field names which are showing up, but not the data itself associated with these field names. So I think my frames in my layout are good. Why is the parent not passing the id number to the child? I'm thinking there must be something wrong with my data model. Any suggestions on creating this type of report?
Thanks for your suggestion. In looking at this some more I see now that the queries are finding my data, but the data is not printing. Simply put, my parent query has student name & number, my child query has attendance dates for that student. The parent portion is working fine with the student name & number appearing on the report, but my child attendance dates are not showing on the report. The repeating frame in which they reside is also not showing. I know the queries are pulling the right data though, because the number of pages I am getting for each student corresponds to that student's attendance data. But the entire frame and data within it are not showing on my report. I have checked to see that the Visible value is set to Yes. Does anyone know what I am overlooking?
-
Parent/Child Master Data Type
I recently created a new master data type in my model, which included one attribute with the 'parent' check box checked - to signify that it was to be used as the parent.
Upon activating the master data type - the system auto generated several other attributes within the master data type. My question is, what is the purpose of these additional attributes and how are they to be used?
Before Activation:
Attribute
Description
Notes
ID
ID
<< marked as key and as required
DESCR
Description
<< no special check boxes checked
PID
Parent ID
<< marked with parent check box
After activation:
Attribute
Description
Notes
ID
ID
<< marked as key and as required
DESCR
Description
<< no special check boxes checked
PID
Parent ID
<< marked with parent check box
IDA
Ancestor: ID
<< auto added after activation
IDL
Level: ID
<< auto added after activation
IDLA
Ancestor: Level: ID
<< auto added after activation
IDPTH
Path: ID
<< auto added after activation
IDPTHA
Ancestor: Path: ID
<< auto added after activation
DEACRA
Ancestor: Description
<< auto added after activation
PIDA
Ancestor: Parent ID
<< auto added after activationhttps://share.sap.com/a:r2l29c/MyAttachments/38b00c31-a7f4-404c-8247-1a99ef4b0509/
Hey JJ,
The purpose of these attributes is for parent-child hierachy relationship.
In addition to above mentioned attributes, you should also notice (via HANA studio), that another Planning object gets generated automatically. The new planning object should be the name of your parent-child object plus "_ANC" prefix at the end.
If you take a look at this planning object, you will notice that the object contains all the generated attributes (your attriubute plus "A" prefix at the end) in the definition.
Once you load data into your parent-child hiearchy object the "_ANC" object will automatically get populated with parent-child node relationship.
"A-prefix" attriubutes essentially represents the attributes of ancestor in this case.
In addition, in order to do Ancestor rolllup in your calculation you will also need to create an ancestor planning level which contains all the attriubutes of your base planning level as well as these "A-Prefix" attributes.
Please take a look at the document we created for "How to configure Parent-Child Hiearchy" from the share link
It has more detailed information.
Thanks.
Daniel. -
Parent-Child Hierarchy Show No Data
Hi:
OBIEE 11.1.1.6.5
I created a parent-child hierarchy following multiple examples in books and on the web. I can pull the presentation hierarchy--by itself--into a view and drill up and down. But when I add a measurement from the fact table, I receive a no data found error. I copied the SQL into SQL*Developer and ran it, and it too returned no data. I've tried to read and debug the query in SQL*Developer, but I don't understand what it is doing.
The dimension table I am using for the parent-child hierarchy has a cost_Center_id and parent_cost_center_id. I used the Parent-Child dimension wizard to create and populate the new hierarchy table.
I can create a view by using the cost_center item and a fact table measurement without the presentation hierarchy, so it has something to do with the presentation hierarchy.
I've been at this for a few days now, and I've run out of ideas. Can anyone suggest what I may have done wrong?
Thanks.check if there is data in the fact table.. Next check also if the join condition between the dimension and fact is valid.
-
Script populate parent-child hierarchy not running
Hallo guys
I have problem when running script populate Parent-Child Relationship Table.
Here is the script.I don't even change the script.just run it in PL/SQL
declare
v_max_depth integer;
v_stmt varchar2(32000);
i integer;
begin
select max(level) into v_max_depth
from V_D_BRANCH
connect by prior BRANCH_KEY=PARENT_BRANCH_KEY
start with PARENT_BRANCH_KEY is null;
v_stmt := 'insert into DM_ANALYTICS.BRANCH_HIERARCHY (MEMBER_KEY, ANCESTOR_KEY, DISTANCE, IS_LEAF)
select BRANCH_KEY as member_key, null, null, 0 from V_D_BRANCH where PARENT_BRANCH_KEY is null
union all
select member_key,
replace(replace(ancestor_key,''\p'', ''|''), ''\'', ''\'') as ancestor_key,
case when depth is null then 0
else max(depth) over (partition by member_key) - depth + 1
end as distance, is_leaf
from
select member_key,depth,
case when depth is null then '' || member_key
when instr(hier_path, ''|'', 1, depth + 1) = 0 then null
else substr(hier_path, instr(hier_path, ''|'', 1, depth) + 1, instr(hier_path, ''|'', 1, depth + 1) - instr(hier_path, ''|'', 1, depth) - 1)
end ancestor_key,
is_leaf
from
( select BRANCH_KEY as member_key, PARENT_BRANCH_KEY as ancestor_key, sys_connect_by_path(replace(replace(BRANCH_KEY, ''\'', ''\''), ''|'', ''\p''), ''|'') as hier_path,
case when BRANCH_KEY in (select PARENT_BRANCH_KEY from V_D_BRANCH ) then 0 else 1 end as IS_LEAF
from V_D_BRANCH
connect by prior BRANCH_KEY = PARENT_BRANCH_KEY
start with PARENT_BRANCH_KEY is null
( select null as depth from dual;
for i in 1..v_max_depth - 1 loop
v_stmt := v_stmt || union all select '' || i || '' from dual;
end loop;
v_stmt := v_stmt || ) )
where ancestor_key is not null;
execute immediate v_stmt;
end;
but I got errors like following:
Error report -
ORA-06550: line 19, column 12:
PLS-00103: Encountered the symbol "insert into DM_ANALYTICS.BRANCH_HIERARCHY (MEMBER_KEY, ANCESTOR_" when expecting one of the following:
( - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable>
continue avg count current exists max min prior sql stddev
sum variance execute forall merge time timestamp interval
date <a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
<an alternatively-quoted string
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
what should I do guys?any idea,any solution would be appreciated.thanks alot guys956850 wrote:
hi,
i tried making "Dimension with Parent-Child Hierarchy" as described in your tutorials.
i finished with the admin tool and database changes and with no errors.
when trying to create a new answer, by only puting the hierarchy column in the answer.
the result show "no result" exist.
i am not sure what i am doing wrong. maybe you can point me to the problem?
thanks
Mirit.Hi Mirit,
What is the table that you created hierarchy on?
Which column in the hierarchy you pulled into your reports to see the No Result message?
Please query the table and see if has data.
Thanks,
G. SK -
Export Parent Child Report data
Hello,
Does anyone know if it is possible to export Child - parent report data in one file?
Kind regards,
OliThanks for your suggestion. In looking at this some more I see now that the queries are finding my data, but the data is not printing. Simply put, my parent query has student name & number, my child query has attendance dates for that student. The parent portion is working fine with the student name & number appearing on the report, but my child attendance dates are not showing on the report. The repeating frame in which they reside is also not showing. I know the queries are pulling the right data though, because the number of pages I am getting for each student corresponds to that student's attendance data. But the entire frame and data within it are not showing on my report. I have checked to see that the Visible value is set to Yes. Does anyone know what I am overlooking?
-
Overriding VO Impl class methods to populate parent-child VO
Hi All,
I need to populate parent child VOs by giving webservice calls from respective impl classes.
Scenario : Lets say suppose i have 2 VOs as DepartmentVO and Employee VO with a viewLink on departmentId. Taking a particular instance, in Department table there are 2 rows and for each parent row we have 2 child rows in Employee.
Webservice Structure : I have a parent Object and inside that parent object i have list of child objects
e.g : public class DepartmentDTO{
private List<EmployeeDTO> employeeList;
After that i have extended Impl classes for both VOs and overriden method i.e. "executeQueryForCollection" to give a webservice call and get back response of DepartmentDTO[] with List<EmployeeDTO> inside it.
In DepartmenntVOImpl class i have overriden "createRowFromResultSet" which populates the parent VO with the number of parent records returned from webservice.
Code for Department impl class is :
protected ViewRowImpl createRowFromResultSet(Object qc,
ResultSet resultSet) {
Iterator deptIter= getPackageClassIterator(qc);
ViewRowImpl r = createNewRowForCollection(qc);
DepartmentDTO curDTO = (DepartmentDTO )deptIter.next();
populateAttributeForRow(r,
findAttributeDef("DeptId").getIndex(),
curDTO.geDeptId() );
populateAttributeForRow(r,
findAttributeDef("DeptName").getIndex(),
curDTO.getDeptName() );
return r;
Similarly i have overridden "createRowFromResultSet" method in EmployeeVOImpl to populate the child VO(this need to be populated from the list object inside parent object reponse)
Code as follows :
protected ViewRowImpl createRowFromResultSet(Object qc,
ResultSet resultSet) {
Iterator empItr= getPackageClassIterator(qc);
ViewRowImpl r = createNewRowForCollection(qc);
DepartmentDTO curDTO1 = (DepartmentDTO )empItr.next();
List<EmployeeDTO> list = curDTO1.getEmployeesList();
for (EmployeeDTO curDTO : list) {
populateAttributeForRow(r,
findAttributeDef("EmpId").getIndex(),
curDTO.getEmpId());
populateAttributeForRow(r,
findAttributeDef("EmpName").getIndex(),
curDTO.getEmpName() );
populateAttributeForRow(r,
findAttributeDef("EmpLastName").getIndex(),
curDTO.getEmpLastName() );
populateAttributeForRow(r,
findAttributeDef("DeptId").getIndex(),
curDTO.getDeptId());
return r;
Though the code looks simple and correct but the child records are not getting populated correctly. Am not sure if the code implementation to populate parent child VOs from webservcie is correct or not.
Would appreciate for Help or valuable Suggestions.
-SanjeebHi Ray,
Go for custom BADIs in this case. In fact, that is exactly the functionality you are looking for !
Just go through this excellent five part blog on Enhancement framework by Thomas Weiss.
What the New Enhancement Framework Is For Its Basic Structure and Elements For Beginners
The new Enhancement Framework Part 2 - What Else You Need to Know Before Building an Enhancement
How To Define a New BAdI Within the Enhancement Framework - Part 3 of the Series
How to implement a BAdI And How to Use a Filter - Part 4 of the Series on the New Enhancement Framework
Source Code Enhancements - Part 5 of the Series on the New Enhancement Framework
Cheers,
Mahesh -
No data for Parent-child hierarchy column in Pivot table view
Hi all,
I used OBIEE 11.1.1.6.2 Version.
I drag one Parent-child hierarchy column and one measure and show result with a pivot table view.
But when I click "+" icon to show detail level data,
It messaged that: "*the layout of this view combined with the data,selections,drills,or prompt values chosen resulted in no data*."
But it can show every-level data when I used table view.
It was so strange..
Did anybody meet this before?
Thanks in advance.
regards,
AnneHi,
Yes, I have the same problem with pivot table for hierarchy dimension.
If you use a normal table (not pivot) it seem to work. Unfortunatley with restrictions as normal table view have.
Same problem still exist in 11.1.1.6.5
I have logged a SR to Oracle about this. -
How to delete parent table data even though it has child records
hi all,
How to delete parent table data even though it has child records.
ex: delete from pa_request cascade constraints;
But this command is not working .
Regards,
P Prakash833560 wrote:
ex: delete from pa_request cascade constraints;cascade constraints is DROP table option. It can't be used with DELETE. You need to delete child rows first or drop foreign keys and recreate them with ON DELETE CASCADE. Then:
delete from pa_request will automatically delete child rows. However, personally I don't like ON DELETE CASCADE. You can, by mistake, delete half of your database without even realizing it.
SY. -
SubSelect Not filter data for Parent/Child hierarchy
I have data for my parent /child dimension like that
DimCust
Fact Sal
Customer ID
Parent ID
Customer Type
Product Id
Customer ID
Year
Sales
1
1
Retailer
4
1
2015
100
2
1
Retailer
4
2
2014
200
3
3
Retailer
4
3
2014
300
4
3
Retailer
4
4
2015
400
5
5
Retailer
4
5
2015
500
In my query,
I use sub select to filter
data for year 2014c and product id 4, when I got result
it’s missed the aggregation of customer id 1 and 4.
Even I try to pass in where clause it’s also not give correct result.
code,
with
set ba EXISTS([DIMCustomer].[Level 02].allmembers, [DIMCustomer].[Hierarchy].&[MyHierarchy],"factTable")
SELECT
[Measures].[Sales]
} ON 0,
[ba]on 1
FROM (SELECT ( { [CropYear].[CropYear].&[2014] } ) ON COLUMNS
FROM (SELECT ( { [DimProduct].[ProductID].[4] } ) ON COLUMNS
FROM [myCube]))
please help me on this, what is the best practices.
Regards,
ManishHi manishcal16PPS,
According to your description, you want to slice the fact data on Year 2014 and Product 4. Now you find the result missing the customer 1 and 4. Right?
In this scenario, based on your Fact Sal table, both customer 1 and 4 are on Year 2015. So when you filter the data, it will not show customer 1 and 4. It returns correct result. For filtering data, either using sub select or specifying slicer axis
can achieve your requirement.
Reference:
Specifying the Contents of a Slicer Axis (MDX)
Best Regards,
Simon Hou
TechNet Community Support -
Sum within a self-contained parent-child table
I have two tables - a "key" table containing a multi-layer parent-child relationship, and an "amount" table containing the keys for the leaf nodes in the key table as well as numeric values (e.g. amounts).
I want a query that returns each row in the key table as well as the sum of the amount table's amounts for all of that key's leaf nodes (so the root node would have the sum of all of the amount values).
Here's what I mean - I have two tables, KEY and AMOUNT
KEY has two columns, key and parent_key; key and parent_key have a CONNECT BY relationship on parent_key = prior key (with parent_key null for the root):
KEY PARENT_KEY
0 null
1 0
2 0
3 0
1A 1
2A 2
2B 2
3A 3
3B 3
3C 3
1A1 1A
1A2 1A
2A1 2A
2A2 2A
2B1 2B
3A1 3A
3A2 3A
3C1 3C
3C2 3CAMOUNT has two columns, key and amount; key points to KEY.key, and amount is a value for that particular key
(note that all key values are leaf nodes in the KEY table)
KEY AMOUNT
1A1 1
1A2 2
2A1 3
2A2 4
2B1 5
3A1 6
3A2 7
3C1 8
3C2 9 What I want is a result that looks like this, where each key's amount is the sum of its eventual leaf keys' amounts
KEY AMOUNT
0 45
1 3
2 12
3 30
1A 3
2A 7
2B 5
3A 13
3B 0
3C 17
1A1 1
1A2 2
2A1 3
2A2 4
2B1 5
3A1 6
3A2 7
3C1 8
3C2 9For example, key 2A's value, 7, is the sum of the values of 2A1 and 2A2; key 3's value is the sum of 3A1, 3A2, 3C1, and 3C2.
Is there a way of doing this with a single query?
The idea I came up with is, do a select on KEY with a "CONNECT_BY_PATH key" column so each row includes a string containing the keys of all of its ancestors, and then do a join on AMOUNT with amount.key IN the CONNECT_BY_PATH column; however, with a larger amount of data, this takes quite a bit of time. Is there a faster / more obvious way of doing this?SQL> with key_tbl as (
2 select '0' key,null parent_key from dual union all
3 select '1','0' from dual union all
4 select '2','0' from dual union all
5 select '3','0' from dual union all
6 select '1A','1' from dual union all
7 select '2A','2' from dual union all
8 select '2B','2' from dual union all
9 select '3A','3' from dual union all
10 select '3B','3' from dual union all
11 select '3C','3' from dual union all
12 select '1A1','1A' from dual union all
13 select '1A2','1A' from dual union all
14 select '2A1','2A' from dual union all
15 select '2A2','2A' from dual union all
16 select '2B1','2B' from dual union all
17 select '3A1','3A' from dual union all
18 select '3A2','3A' from dual union all
19 select '3C1','3C' from dual union all
20 select '3C2','3C' from dual
21 ),
22 amount_tbl as (
23 select '1A1' key,1 amount from dual union all
24 select '1A2',2 from dual union all
25 select '2A1',3 from dual union all
26 select '2A2',4 from dual union all
27 select '2B1',5 from dual union all
28 select '3A1',6 from dual union all
29 select '3A2',7 from dual union all
30 select '3C1',8 from dual union all
31 select '3C2',9 from dual
32 )
33 select key,
34 nvl(sum(amount),0) amount
35 from (
36 select connect_by_root k.key key,
37 amount
38 from key_tbl k,
39 amount_tbl a
40 where a.key(+) = k.key
41 connect by k.parent_key = prior k.key
42 )
43 group by key
44 order by key
45 /
KEY AMOUNT
0 45
1 3
1A 3
1A1 1
1A2 2
2 12
2A 7
2A1 3
2A2 4
2B 5
2B1 5
KEY AMOUNT
3 30
3A 13
3A1 6
3A2 7
3B 0
3C 17
3C1 8
3C2 9
19 rows selected.
SQL> SY. -
Update data to upper case in parent/child tables
Hi Gurus!
In production we have a product table and which is being reference by many tables making it parent child relationship. By mistake, we realized that last month some product were added in lower case and now we got a request to update all these product codes to upper case so that the existing code that use these tables have no impact. Appreciate if you can give some idea on how can I update the existing data in the parent table to upper case along with the child records?
Regards
SriAre the product code that you need to update what is stored in the child tables? If so, then you would need to do it in several steps, something like:
Identify the child tables
SELECT table_name, constraint_name
FROM user_constraints
WHERE r_constraint_name = (SELECT constraint_name
FROM user_constraints
WHERE table_name = 'PRODUCT_TABLE' and
constraint_type = 'P');Create the new upper case product code in product table:
INSERT INTO product_table
SELECT UPPER(product_code), other_columns
FROM product_table
WHERE product_code <> UPPER(product_code);Update the child tables to uppercase the product codes
UPDATE child1
SET product_code = UPPER(product_code)
WHERE product_code <> UPPER(product_code);finally, delete the lower case product codes from product_table
DELETE FROM product_table
WHERE product_code <> UPPER(product_code);John -
What is data sets,parent data,child data in generic technology connector..
Hi All,
I am a new learner to OIM. Please try to give a brief details of data sets,child data,parent data,providers in Generic Technology Connectors..
Thanks in advance..Description:
You get this error, if you are passing reserved key words to the XML Parser or the XML syntax is wrong.
Cause:
I suppose, you are getting this error from tcImportOperationsIntf's addXMLFile() method. From your error message it looks like, when a file is submitted to XML Parser during the import operation, syntax is wrong.
Solution:
Check the code that is generating the xml file. Easy way to test is : open the xml file in IE. If there is syntax error, IE will throw you the error.
Hope this helps you.
Cheers,
Raghavendra
Maybe you are looking for
-
Material column is not displayed in ME21N in NEW ECC 6.0 - Urgent
Hi Gurus I am working in Technical upgradation from 4.6 C to ECC 6.0 We got new system last week only, in the new system (6.0) in ME21N - the filed for entering material no is not coming. Please suggest Muthu kumar
-
OK OK OK this is long but very very important i live on music...... SO i thought i would organized my iTunes Library but i would do it from the music folder.........BAD IDEA.... i duplicated my music folder just INCASE something bad hap
-
Data acquisition from SPCM-AQRH-15 and Nano-ViewTM 200-2/M
I am trying to acquire data from APDs (PerkinElmer, SPCM-AQRH-15) and Nanopositioner (Mad City, Nano-ViewTM 200-2/M). The second equipment has USB 162 or 202 digital interface integrated but I am not sure abut the first one since I am still waiting m
-
Hi All, We need to do FTP some files from remote server and files are to be pgp encrypted or decrypted.Can you please tell is there some way to use pgp encryption in FTP adapter. If yes, please provide some link for documentation. or shall we do ftp
-
In production order backflush how components select valuation type
Hi, i am using backflush in production order planning where components have valuation type. when i stage them i give the valuation type. but when i confirm a operation the backflush is giving problem. the problem is i have to enter the valuation