473,789 Members | 2,561 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 1625
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
1484
by: gsoftwares | last post by:
HI Gurus, I have xml file in this format <hierarchy> <entity> <contents> <entity> </entity> </contents>
2
1747
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
2610
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
3811
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
7657
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
1608
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
1337
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
1448
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
3457
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
9663
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
9506
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10404
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...
0
10193
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9979
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...
0
9016
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7525
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
6761
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
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.