PHP behaves strange when capturing 'return' value, how to over come?
when i echo the value inside the function, it works fine.
if i return a value from the function, it return nothing... why?
Assume, that the following is the table 'menu' and having the following fields(with values)
//php code
[code=php]
<?
include "db.php";
$returnval=trac e_child(1,4);
echo $returnval;
function trace_child($pa rent,$child)
{
$result = mysql_query('SE LECT * FROM menu
WHERE parentmenuid='. $parent);
while ($row = mysql_fetch_arr ay($result))
{
if($child==$row['menuid'])
{
return true; ///the problem is here.. if i put echo 'true'; then it works fine... why
}
else{
trace_child($ro w['menuid'],$child);}
}
}
?>
[/code]
i wants to trace whether menu '4' is grandchild of menu'1' .
please somebody help me...
when i echo the value inside the function, it works fine.
if i return a value from the function, it return nothing... why?
Assume, that the following is the table 'menu' and having the following fields(with values)
Code:
menuid ====== 1 2 3 4 5 parentmenuid ========== 0 1 1 5 1
[code=php]
<?
include "db.php";
$returnval=trac e_child(1,4);
echo $returnval;
function trace_child($pa rent,$child)
{
$result = mysql_query('SE LECT * FROM menu
WHERE parentmenuid='. $parent);
while ($row = mysql_fetch_arr ay($result))
{
if($child==$row['menuid'])
{
return true; ///the problem is here.. if i put echo 'true'; then it works fine... why
}
else{
trace_child($ro w['menuid'],$child);}
}
}
?>
[/code]
i wants to trace whether menu '4' is grandchild of menu'1' .
please somebody help me...
Comment