473,890 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Returning 0 for level in hierarchy query

salesmr
6 New Member
I have a query that works fine in Oracle, but I can't seem to get it to work in PHP. The code is:
Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT lpad(' ', (level - 1) * 4) || emp_name, level ";
  2. $query .= "from emp_table";
  3. $query .= "CONNECT BY manager_id = prior emp_id ";
  4. $query .= "START WITH emp_id = '1234567' ";
  5.  
  6. $result = odbc_do($connection, $query);
  7.  
  8. while(odbc_fetch_into($result,&$fields))
  9. {
  10.     $empname = $fields[0];
  11.                 $level = $fields[1];
  12.  
  13.     $indent = (($level - 1) * 4);
  14.     for($x=0;$x<$indent;$x++)
  15.     {
  16.     print("&nbsp;");
  17.     }
  18.     print("$empname<br>");
  19. }
[Please use CODE tags when posting source code. Thanks! --pbmods]

I am trying to return an indented hierarchy. It works if I create a view and select the data from there, and also when I print the query and run it directly in Oracle, but always returns "0" as $level in PHP.

Could you please advise?

Thank you in advance for your assistance,
Michelle
Jun 17 '07 #1
7 1631
ak1dnar
1,584 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $query = "SELECT lpad(' ', (level - 1) * 4) || emp_name, level ";
  3. $query .= "from emp_table";
  4. $query .= "CONNECT BY manager_id = prior emp_id ";
  5. $query .= "START WITH emp_id = '1234567' ";
  6.  
  7. echo $query;
  8. ?>
  9.  
outputs:
Refer to the bold area of the output.It has merged each other.
Expand|Select|Wrap|Line Numbers
  1. SELECT lpad(' ', (level - 1) * 4) || emp_name, level from emp_tableCONNECT BY manager_id = prior emp_id START WITH emp_id = '1234567'
change this line
Expand|Select|Wrap|Line Numbers
  1. $query .= "from emp_table";
with
Expand|Select|Wrap|Line Numbers
  1. $query .= "from emp_table ";
it will work.
Jun 17 '07 #2
ak1dnar
1,584 Recognized Expert Top Contributor
I hope you might read Posting Guidelines before your next post.

You are welcome to TSDN.
best regards,
-Ajaxrand
Jun 17 '07 #3
salesmr
6 New Member
I actually had it right in my code, just when I copied it over and took out some unneeded stuff to post it, I accidentally removed the space at the end. It still is returning "0" for level.

Would appreciate any info you can give. (By the way, this is my 1st post, so sorry for any inconvenience.)

Thanks
Jun 17 '07 #4
salesmr
6 New Member
Mr. Moderator,
Can you please advise? I am stuck on this. I know that "level" is a field/pseudocolumn in Oracle that I can use to tell me what level my recursive query results are at. This works great in Oracle, but when I try it in PHP, it always returns "0" as my level rather than 1,2,3,4, etc. I would appreciate any assistance that you can give. I'm stumped.

Thanks,
Michelle
Jun 17 '07 #5
ak1dnar
1,584 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT lpad(' ', (level - 1) * 4) || emp_name, level ";
  2. $query .= "from emp_table";
  3. $query .= "CONNECT BY manager_id = prior emp_id ";
  4. $query .= "START WITH emp_id = '1234567' ";
  5.  
  6. $result = odbc_do($connection, $query);
  7.  
  8. while(odbc_fetch_into($result,&$fields))// HAVE YOU NOTICED THIS "&" IN YOUR odbc_fetch_into, MAY I KNOW WHAT IS IT ?
  9. {
  10. $empname = $fields[0];
  11. $level = $fields[1];
  12.  
  13. $indent = (($level - 1) * 4);
  14. for($x=0;$x<$indent;$x++)
  15. {
  16. print("&nbsp;");
  17. }
  18. print("$empname<br>");
  19. }
Jun 18 '07 #6
salesmr
6 New Member
Honestly, I've never even noticed it before, and I've been copying that same general code from application to application. I removed it and it still behaved the same way.....not sure.
Jun 19 '07 #7
ak1dnar
1,584 Recognized Expert Top Contributor
Honestly, I've never even noticed it before, and I've been copying that same general code from application to application. I removed it and it still behaved the same way.....not sure.
I am not familiar with oracle odbc, better you refer to these sample application and functions under php.net
Thanks,
-Ajaxrand
Jun 19 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1487
by: gsoftwares | last post by:
HI Gurus, I have xml file in this format <hierarchy> <entity> <contents> <entity> </entity> </contents>
2
1749
by: nicolec | last post by:
I've been tearing my hair out over this UDF. The code works within a stored procedure and also run ad-hoc against the database, but does not run properly within my UDF. We've been using the SP, but I do need a UDF instead now. All users, including branch office, sub-companies and companies and so on up the lines are in the same table. I need a function which returns a row for each level, eventually getting to the master company all...
4
2612
by: Daisy | last post by:
Let's say I've got a forum, where users can be moderators of each forum. Tables look like this: USER -------- user_key name FORUM
25
3827
by: lucas_denoir | last post by:
I'm having some serious trouble accessing a virtual method of a base class - that is not the immidate base class. This is the basic situation that I have: =========================================================== class A { public virtual string PrintMe() {
6
7661
by: SQL Server | last post by:
I've been working this for a while. Kind of new to SQL Server functions and not seeing what I am doing wrong. I have this function CREATE FUNCTION dbo.test (@Group varchar(50)) RETURNS smalldatetime AS BEGIN Declare @retVal varchar(10) (SELECT @retVal= MIN() FROM dbo.t_master_schedules WHERE (event_id = 13) AND (group_ =@Group)) return convert(smalldatetime, @retVal, 1)
1
1609
by: Gary Wessle | last post by:
Hi is there some guide lines on how many level deep once can structure the inheritance, I have 3 level deep inheritance setup and just wondering whether this is the norm? each level is generated by the presence of commonality in concept between the classes. thanks
2
1341
by: Tem | last post by:
I have a table that looks like this. Each row is a reply or a topic when IsAReplyTo = 0 I need to write a query that pulls all rows of a hierarchy of a given ID Table Forum ID IsAReplyTo 4 0 9 4 27 4 63 27
3
1453
by: Mike P | last post by:
In some of the code I am looking at on a sample website, a lot of methods are returning interfaces such as IDataReader instead of a plain DataReader. Why would you want to do this? *** Sent via Developersdex http://www.developersdex.com ***
2
3465
by: ndeeley | last post by:
Hello, I've written a script which returns the admin rights of users in a table - their access level, and their priviledges. The priviledge are returned to a check box and the admin rights to a drop down list. I want this list to have more than one value so that it can be altered. I've created a loop to run through the drop down options and select the one that matches in the database. However it doesn't appear to be working - its not...
0
9976
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10904
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8007
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7159
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5834
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6034
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4662
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.