I have a query that works fine in Oracle, but I can't seem to get it to work in PHP. The code is: - $query = "SELECT lpad(' ', (level - 1) * 4) || emp_name, level ";
-
$query .= "from emp_table";
-
$query .= "CONNECT BY manager_id = prior emp_id ";
-
$query .= "START WITH emp_id = '1234567' ";
-
-
$result = odbc_do($connection, $query);
-
-
while(odbc_fetch_into($result,&$fields))
-
{
-
$empname = $fields[0];
-
$level = $fields[1];
-
-
$indent = (($level - 1) * 4);
-
for($x=0;$x<$indent;$x++)
-
{
-
print(" ");
-
}
-
print("$empname<br>");
-
}
[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
7 1625 ak1dnar 1,584
Recognized Expert Top Contributor - <?php
-
$query = "SELECT lpad(' ', (level - 1) * 4) || emp_name, level ";
-
$query .= "from emp_table";
-
$query .= "CONNECT BY manager_id = prior emp_id ";
-
$query .= "START WITH emp_id = '1234567' ";
-
-
echo $query;
-
?>
-
outputs:
Refer to the bold area of the output.It has merged each other. - 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 - $query .= "from emp_table";
with - $query .= "from emp_table ";
it will work.
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
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
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
ak1dnar 1,584
Recognized Expert Top Contributor - $query = "SELECT lpad(' ', (level - 1) * 4) || emp_name, level ";
-
$query .= "from emp_table";
-
$query .= "CONNECT BY manager_id = prior emp_id ";
-
$query .= "START WITH emp_id = '1234567' ";
-
-
$result = odbc_do($connection, $query);
-
-
while(odbc_fetch_into($result,&$fields))// HAVE YOU NOTICED THIS "&" IN YOUR odbc_fetch_into, MAY I KNOW WHAT IS IT ?
-
{
-
$empname = $fields[0];
-
$level = $fields[1];
-
-
$indent = (($level - 1) * 4);
-
for($x=0;$x<$indent;$x++)
-
{
-
print(" ");
-
}
-
print("$empname<br>");
-
}
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.
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: gsoftwares |
last post by:
HI Gurus,
I have xml file in this format
<hierarchy>
<entity>
<contents>
<entity>
</entity>
</contents>
|
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...
|
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
|
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()
{
|
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)
| |
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
|
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
|
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 ***
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |