470,870 Members | 1,400 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,870 developers. It's quick & easy.

recursive function calling by reference

Hello,
I'm using a recursive function to get an array of ID from a database passing
the array by reference.

I need this structure for the function because the database structure is
like a tree and there is no limit of level.

Here is the code :

__________________________________________________ __
function remplir_tableau($id, &$arrayOfAllElem)
{
$arrayOfAllElem[] = $id;
$req_ksup = mysql_query("select kinf_ksup,nume_kard,soci_kard
from kardex_superieur
left join kardex on id_kard=kinf_ksup
where ksup_ksup='$id' ");

while ($row = mysql_fetch_array($req_ksup, MYSQL_NUM))
{
remplir_tableau($row[0], &$arrayOfAllElem);
}
}
remplir_tableau($id_kard, $TabKard);
__________________________________________________ ___


but if I don't change the php.ini file allow_call_time_pass_reference to
true I have a message :

Warning: Call-time pass-by-reference has been deprecated - argument passed
by value; If you would like to pass it by reference, modify the declaration
of [runtime function name](). If you would like to enable call-time
pass-by-reference, you can set allow_call_time_pass_reference to true in
your INI file. However, future versions may not support this any longer.
I have the error message but the function seems to work anyway !
Is there any way else to do that ? ... or to not have the message ?
Thanks a lot for helping !

Stéphanie
Apr 5 '06 #1
3 2098
Stephanie Le Gall wrote:
I have the error message but the function seems to work anyway !
Is there any way else to do that ? ... or to not have the message ?


Change the recursive call to:

function remplir_tableau($id, &$arrayOfAllElem)
{
.....
remplir_tableau($row[0], $arrayOfAllElem);
}
}

JW

Apr 5 '06 #2
Thanks a lot !!!!

I've juste seen my error ... And I feel terrible sending a post like that
!!!

Stéphanie
"Janwillem Borleffs" <jw@jwscripts.com> a écrit dans le message de
news:44**************@jwscripts.com...
Stephanie Le Gall wrote:
I have the error message but the function seems to work anyway !
Is there any way else to do that ? ... or to not have the message ?


Change the recursive call to:

function remplir_tableau($id, &$arrayOfAllElem)
{
.....
remplir_tableau($row[0], $arrayOfAllElem);
}
}

JW

Apr 5 '06 #3
Stephanie Le Gall wrote:
Hello,
I'm using a recursive function to get an array of ID from a database passing
the array by reference.

I need this structure for the function because the database structure is
like a tree and there is no limit of level.


Just a suggestion. Retrieving a tree from the database in the manner
you described can be expensive, since every nodes would trigger a
separate query. Usually what I do in a situation like this is to add a
column holding the id to the root of the tree, so that I could retrieve
all the rows at once. Then I use a recursive function to build the
tree.

Apr 5 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Ryan Stewart | last post: by
11 posts views Thread by randomtalk | last post: by
9 posts views Thread by Csaba Gabor | last post: by
2 posts views Thread by aaragon | last post: by
3 posts views Thread by from.future.import | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.